Vector2 Structure |
Namespace: Godot
[SerializableAttribute] public struct Vector2 : IEquatable<Vector2>
The Vector2 type exposes the following members.
Name | Description | |
---|---|---|
Vector2(Vector2) |
Constructs a new Vector2 from an existing Vector2.
| |
Vector2(Single, Single) |
Constructs a new Vector2 with the given components.
|
Name | Description | |
---|---|---|
Down |
Down unit vector. Y is down in 2D, so this vector points +Y.
| |
Inf |
Infinity vector, a vector with all components set to `Mathf.Inf`.
| |
Item |
Access vector components using their index.
| |
Left |
Left unit vector. Represents the direction of left.
| |
NegOne |
Deprecated, please use a negative sign with One instead.
| |
One |
One vector, a vector with all components set to `1`.
| |
Right |
Right unit vector. Represents the direction of right.
| |
Up |
Up unit vector. Y is down in 2D, so this vector points -Y.
| |
Zero |
Zero vector, a vector with all components set to `0`.
|
Name | Description | |
---|---|---|
Abs |
Returns a new vector with all components in absolute values (i.e. positive).
| |
Angle |
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)`.
| |
AngleTo |
Returns the angle to the given vector, in radians.
| |
AngleToPoint |
Returns the angle between the line connecting the two points and the X axis, in radians.
| |
Aspect |
Returns the aspect ratio of this vector, the ratio of `x` to `y`.
| |
Bounce |
Returns the vector "bounced off" from a plane defined by the given normal.
| |
Ceil |
Returns a new vector with all components rounded up (towards positive infinity).
| |
Clamped |
Returns the vector with a maximum length by limiting its length to `length`.
| |
Cross |
Returns the cross product of this vector and `b`.
| |
CubicInterpolate |
Performs a cubic interpolation between vectors `preA`, this vector, `b`, and `postB`, by the given amount `t`.
| |
DirectionTo |
Returns the normalized vector pointing from this vector to `b`.
| |
DistanceSquaredTo |
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.
| |
DistanceTo |
Returns the distance between this vector and `to`.
| |
Dot |
Returns the dot product of this vector and `with`.
| |
Equals(Object) | (Overrides ValueTypeEquals(Object).) | |
Equals(Vector2) | ||
Floor |
Returns a new vector with all components rounded down (towards negative infinity).
| |
GetHashCode | (Overrides ValueTypeGetHashCode.) | |
GetType | (Inherited from Object.) | |
Inverse |
Returns the inverse of this vector. This is the same as `new Vector2(1 / v.x, 1 / v.y)`.
| |
IsEqualApprox |
Returns true if this vector and `other` are approximately equal, by running
IsEqualApprox(Single, Single) on each component.
| |
IsNormalized |
Returns true if the vector is normalized, and false otherwise.
| |
Length |
Returns the length (magnitude) of this vector.
| |
LengthSquared |
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.
| |
LinearInterpolate(Vector2, Vector2) |
Returns the result of the linear interpolation between
this vector and `to` by the vector amount `weight`.
| |
LinearInterpolate(Vector2, Single) |
Returns the result of the linear interpolation between
this vector and `to` by amount `weight`.
| |
MaxAxis |
Returns the axis of the vector's largest value. See Vector2Axis.
If both components are equal, this method returns X.
| |
MinAxis |
Returns the axis of the vector's smallest value. See Vector2Axis.
If both components are equal, this method returns Y.
| |
MoveToward |
Moves this vector toward `to` by the fixed `delta` amount.
| |
Normalized |
Returns the vector scaled to unit length. Equivalent to `v / v.Length()`.
| |
Perpendicular |
Returns a perpendicular vector rotated 90 degrees counter-clockwise
compared to the original, with the same length.
| |
PosMod(Single) |
Returns a vector composed of the PosMod(Single, Single) of this vector's components and `mod`.
| |
PosMod(Vector2) |
Returns a vector composed of the PosMod(Single, Single) of this vector's components and `modv`'s components.
| |
Project |
Returns this vector projected onto another vector.
| |
Reflect |
Returns this vector reflected from a plane defined by the given `normal`.
| |
Rotated |
Rotates this vector by `phi` radians.
| |
Round |
Returns this vector with all components rounded to the nearest integer,
with halfway cases rounded towards the nearest multiple of two.
| |
Set(Vector2) | Obsolete. | |
Set(Single, Single) | Obsolete. | |
Sign |
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.
| |
Slerp |
Returns the result of the spherical linear interpolation between
this vector and `to` by amount `weight`.
Note: Both vectors must be normalized.
| |
Slide |
Returns this vector slid along a plane defined by the given normal.
| |
Snapped |
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.
| |
Tangent |
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.
| |
ToString | (Overrides ValueTypeToString.) | |
ToString(String) |
Name | Description | |
---|---|---|
x |
The vector's X component. Also accessible by using the index position `[0]`.
| |
y |
The vector's Y component. Also accessible by using the index position `[1]`.
|