API > Vector2
Vector2⚓︎
Representation of 2D vectors and points. Unity Vector2
Members⚓︎
Properties⚓︎
Name | Description |
---|---|
Vector2 .magnitude |
Returns the length of this vector (Read Only). |
Vector2 .normalized |
Returns this vector with a magnitude of 1 (Read Only). |
Vector2 .sqrMagnitude |
Returns the squared length of this vector (Read Only). |
Vector2 .x |
X component of the vector. |
Vector2 .y |
Y component of the vector. |
Static Properties⚓︎
Name | Description |
---|---|
Vector2 .down |
Shorthand for writing Vector2(0, -1). |
Vector2 .left |
Shorthand for writing Vector2(-1, 0). |
Vector2 .negativeInfinity |
Shorthand for writing Vector2(float.NegativeInfinity, float.NegativeInfinity). |
Vector2 .one |
Shorthand for writing Vector2(1, 1). |
Vector2 .positiveInfinity |
Shorthand for writing Vector2(float.PositiveInfinity, float.PositiveInfinity). |
Vector2 .right |
Shorthand for writing Vector2(1, 0). |
Vector2 .up |
Shorthand for writing Vector2(0, 1). |
Vector2 .zero |
Shorthand for writing Vector2(0, 0). |
Constructor⚓︎
Name | Description |
---|---|
Vector2(x, y) |
Constructs a new vector with given x, y components. |
Methods⚓︎
Name | Description |
---|---|
Vector2 .Equals(other) |
Returns true if the given vector is exactly equal to this vector. |
Vector2 .Normalize() |
Makes this vector have a magnitude of 1. |
Vector2 .Set(newX, newY) |
Set x and y components of an existing Vector2. |
Static Methods⚓︎
Name | Description |
---|---|
Vector2 .Angle(from, to) |
Returns the unsigned angle in degrees between from and to. |
Vector2 .ClampMagnitude(vector, maxLength) |
Returns a copy of vector with its magnitude clamped to maxLength. |
Vector2 .Distance(a, b) |
Returns the distance between a and b. |
Vector2 .Dot(lhs, rhs) |
Dot Product of two vectors. |
Vector2 .Lerp(a, b, t) |
Linearly interpolates between vectors a and b by t. |
Vector2 .LerpUnclamped(a, b, t) |
Linearly interpolates between vectors a and b by t. |
Vector2 .Max(lhs, rhs) |
Returns a vector that is made from the largest components of two vectors. |
Vector2 .Min(lhs, rhs) |
Returns a vector that is made from the smallest components of two vectors. |
Vector2 .MoveTowards(current, target, maxDistanceDelta) |
Moves a point current towards target. |
Vector2 .Perpendicular(inDirection) |
Returns the 2D vector perpendicular to this 2D vector. The result is always rotated 90-degrees in a counter-clockwise direction for a 2D coordinate system where the positive Y axis goes up. |
Vector2 .Reflect(inDirection, inNormal) |
Reflects a vector off the vector defined by a normal. |
Vector2 .Scale(a, b) |
Multiplies two vectors component-wise. |
Vector2 .SignedAngle(from, to) |
Returns the signed angle in degrees between from and to. |
Operators⚓︎
Name | Description |
---|---|
Operator (Vector2-Vector2) | Subtracts one vector from another. |
| Unary Operator (-Vector2) | Negates a vector. Each component in the result is negated. |
| Operator (Vector2*number) | Multiplies a vector by a number. |
| Operator (number*Vector2) | Multiplies a vector by a number. |
| Operator (Vector2*Vector2) | Multiplies a vector by another vector. Multiplies each component of lhs by its matching component from rhs. |
| Operator (Vector2/number) | Divides a vector by a number. |
| Operator (Vector2+Vector2) | Adds two vectors. Adds corresponding components together. |
| Operator (Vector2==Vector2) | Returns true if two vectors are approximately equal. To allow for floating point inaccuracies, the two vectors are considered equal if the magnitude of their difference is less than 1e-5. |
| Implicit Cast Operator (Vector3) | Converts a Vector2 to a Vector3. |