Click or drag to resize

Vector2 Methods

The Vector2 type exposes the following members.

Methods
  NameDescription
Public methodAbs
Returns a new vector with all components in absolute values (i.e. positive).
Public methodAngle
Returns this vector's angle with respect to the X axis, or (1, 0) vector, in radians. Equivalent to the result of Atan2(Single, Single) when called with the vector's `y` and `x` as parameters: `Mathf.Atan2(v.y, v.x)`.
Public methodAngleTo
Returns the angle to the given vector, in radians.
Public methodAngleToPoint
Returns the angle between the line connecting the two points and the X axis, in radians.
Public methodAspect
Returns the aspect ratio of this vector, the ratio of `x` to `y`.
Public methodBounce
Returns the vector "bounced off" from a plane defined by the given normal.
Public methodCeil
Returns a new vector with all components rounded up (towards positive infinity).
Public methodClamped
Returns the vector with a maximum length by limiting its length to `length`.
Public methodCross
Returns the cross product of this vector and `b`.
Public methodCubicInterpolate
Performs a cubic interpolation between vectors `preA`, this vector, `b`, and `postB`, by the given amount `t`.
Public methodDirectionTo
Returns the normalized vector pointing from this vector to `b`.
Public methodDistanceSquaredTo
Returns the squared distance between this vector and `to`. This method runs faster than DistanceTo(Vector2), so prefer it if you need to compare vectors or need the squared distance for some formula.
Public methodDistanceTo
Returns the distance between this vector and `to`.
Public methodDot
Returns the dot product of this vector and `with`.
Public methodEquals(Object) (Overrides ValueTypeEquals(Object).)
Public methodEquals(Vector2)
Public methodFloor
Returns a new vector with all components rounded down (towards negative infinity).
Public methodGetHashCode (Overrides ValueTypeGetHashCode.)
Public methodGetType (Inherited from Object.)
Public methodInverse
Returns the inverse of this vector. This is the same as `new Vector2(1 / v.x, 1 / v.y)`.
Public methodIsEqualApprox
Returns true if this vector and `other` are approximately equal, by running IsEqualApprox(Single, Single) on each component.
Public methodIsNormalized
Returns true if the vector is normalized, and false otherwise.
Public methodLength
Returns the length (magnitude) of this vector.
Public methodLengthSquared
Returns the squared length (squared magnitude) of this vector. This method runs faster than Length, so prefer it if you need to compare vectors or need the squared length for some formula.
Public methodLinearInterpolate(Vector2, Vector2)
Returns the result of the linear interpolation between this vector and `to` by the vector amount `weight`.
Public methodLinearInterpolate(Vector2, Single)
Returns the result of the linear interpolation between this vector and `to` by amount `weight`.
Public methodMaxAxis
Returns the axis of the vector's largest value. See Vector2Axis. If both components are equal, this method returns X.
Public methodMinAxis
Returns the axis of the vector's smallest value. See Vector2Axis. If both components are equal, this method returns Y.
Public methodMoveToward
Moves this vector toward `to` by the fixed `delta` amount.
Public methodNormalized
Returns the vector scaled to unit length. Equivalent to `v / v.Length()`.
Public methodPerpendicular
Returns a perpendicular vector rotated 90 degrees counter-clockwise compared to the original, with the same length.
Public methodPosMod(Single)
Returns a vector composed of the PosMod(Single, Single) of this vector's components and `mod`.
Public methodPosMod(Vector2)
Returns a vector composed of the PosMod(Single, Single) of this vector's components and `modv`'s components.
Public methodProject
Returns this vector projected onto another vector.
Public methodReflect
Returns this vector reflected from a plane defined by the given `normal`.
Public methodRotated
Rotates this vector by `phi` radians.
Public methodRound
Returns this vector with all components rounded to the nearest integer, with halfway cases rounded towards the nearest multiple of two.
Public methodSet(Vector2) Obsolete.
Public methodSet(Single, Single) Obsolete.
Public methodSign
Returns a vector with each component set to one or negative one, depending on the signs of this vector's components, or zero if the component is zero, by calling Sign(Single) on each component.
Public methodSlerp
Returns the result of the spherical linear interpolation between this vector and `to` by amount `weight`. Note: Both vectors must be normalized.
Public methodSlide
Returns this vector slid along a plane defined by the given normal.
Public methodSnapped
Returns this vector with each component snapped to the nearest multiple of `step`. This can also be used to round to an arbitrary number of decimals.
Public methodTangent
Returns a perpendicular vector rotated 90 degrees counter-clockwise compared to the original, with the same length. Deprecated, will be replaced by Perpendicular in 4.0.
Public methodToString (Overrides ValueTypeToString.)
Public methodToString(String)
Top
See Also