Skip to content

API > Vector2


Vector2⚓︎

Representation of 2D vectors and points. Unity Vector2

Members⚓︎

Properties⚓︎

Name Description
Vector2.magnitudePropertyReadonly Property Returns the length of this vector (Read Only).
Vector2.normalizedPropertyReadonly Property Returns this vector with a magnitude of 1 (Read Only).
Vector2.sqrMagnitudePropertyReadonly Property Returns the squared length of this vector (Read Only).
Vector2.xProperty X component of the vector.
Vector2.yProperty Y component of the vector.

Static Properties⚓︎

Name Description
Vector2.down Static fieldPropertyReadonly Property Shorthand for writing Vector2(0, -1).
Vector2.left Static fieldPropertyReadonly Property Shorthand for writing Vector2(-1, 0).
Vector2.negativeInfinity Static fieldPropertyReadonly Property Shorthand for writing Vector2(float.NegativeInfinity, float.NegativeInfinity).
Vector2.one Static fieldPropertyReadonly Property Shorthand for writing Vector2(1, 1).
Vector2.positiveInfinity Static fieldPropertyReadonly Property Shorthand for writing Vector2(float.PositiveInfinity, float.PositiveInfinity).
Vector2.right Static fieldPropertyReadonly Property Shorthand for writing Vector2(1, 0).
Vector2.up Static fieldPropertyReadonly Property Shorthand for writing Vector2(0, 1).
Vector2.zero Static fieldPropertyReadonly Property Shorthand for writing Vector2(0, 0).

Constructor⚓︎

Name Description
Vector2(x, y)Constructor Constructs a new vector with given x, y components.

Methods⚓︎

Name Description
Vector2.Equals(other) Method Returns true if the given vector is exactly equal to this vector.
Vector2.Normalize() Method Makes this vector have a magnitude of 1.
Vector2.Set(newX, newY) Method Set x and y components of an existing Vector2.

Static Methods⚓︎

Name Description
Vector2.Angle(from, to) Static fieldMethod Returns the unsigned angle in degrees between from and to.
Vector2.ClampMagnitude(vector, maxLength) Static fieldMethod Returns a copy of vector with its magnitude clamped to maxLength.
Vector2.Distance(a, b) Static fieldMethod Returns the distance between a and b.
Vector2.Dot(lhs, rhs) Static fieldMethod Dot Product of two vectors.
Vector2.Lerp(a, b, t) Static fieldMethod Linearly interpolates between vectors a and b by t.
Vector2.LerpUnclamped(a, b, t) Static fieldMethod Linearly interpolates between vectors a and b by t.
Vector2.Max(lhs, rhs) Static fieldMethod Returns a vector that is made from the largest components of two vectors.
Vector2.Min(lhs, rhs) Static fieldMethod Returns a vector that is made from the smallest components of two vectors.
Vector2.MoveTowards(current, target, maxDistanceDelta) Static fieldMethod Moves a point current towards target.
Vector2.Perpendicular(inDirection) Static fieldMethod 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) Static fieldMethod Reflects a vector off the vector defined by a normal.
Vector2.Scale(a, b) Static fieldMethod Multiplies two vectors component-wise.
Vector2.SignedAngle(from, to) Static fieldMethod Returns the signed angle in degrees between from and to.

Operators⚓︎

Name Description
Operator (Vector2-Vector2)Operator Subtracts one vector from another.

| Unary Operator (-Vector2)Operator | Negates a vector. Each component in the result is negated. |

| Operator (Vector2*number)Operator | Multiplies a vector by a number. |

| Operator (number*Vector2)Operator | Multiplies a vector by a number. |

| Operator (Vector2*Vector2)Operator | Multiplies a vector by another vector. Multiplies each component of lhs by its matching component from rhs. |

| Operator (Vector2/number)Operator | Divides a vector by a number. |

| Operator (Vector2+Vector2)Operator | Adds two vectors. Adds corresponding components together. |

| Operator (Vector2==Vector2)Operator | 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)Operator | Converts a Vector2 to a Vector3. |