2-element structure that can be used to represent positions in 2D space or any other pair of numeric values.
Static variables
staticread onlyDOWN:Vector2
Down unit vector. Y is down in 2D, so this vector points +Y.
Value: Equivalent to new Vector2(0, 1)
.
staticread onlyLEFT:Vector2
Left unit vector. Represents the direction of left.
Value: Equivalent to new Vector2(-1, 0)
.
staticread onlyNEG_ONE:Vector2
Deprecated, please use a negative sign with godot.Vector2.one
instead.
Value: Equivalent to new Vector2(-1, -1)
.
staticread onlyONE:Vector2
One vector, a vector with all components set to 1
.
Value: Equivalent to new Vector2(1, 1)
.
staticread onlyRIGHT:Vector2
Right unit vector. Represents the direction of right.
Value: Equivalent to new Vector2(1, 0)
.
Static methods
staticinlineop_Addition(left:Vector2, right:Vector2):Vector2
Operator overload for godot.Vector2
+ godot.Vector2
.
staticinlineop_Division(vec:Vector2, divisor:Float):Vector2
staticinlineop_Division(vec:Vector2, divisorv:Vector2):Vector2
Operator overload for godot.Vector2
/ ((global::System.Single)(Float
)).
staticinlineop_Equality(left:Vector2, right:Vector2):Bool
Operator overload for godot.Vector2
== godot.Vector2
.
staticinlineop_GreaterThan(left:Vector2, right:Vector2):Bool
Operator overload for godot.Vector2
> godot.Vector2
.
staticinlineop_GreaterThanOrEqual(left:Vector2, right:Vector2):Bool
Operator overload for godot.Vector2
>= godot.Vector2
.
staticinlineop_Inequality(left:Vector2, right:Vector2):Bool
Operator overload for godot.Vector2
!= godot.Vector2
.
staticinlineop_LessThan(left:Vector2, right:Vector2):Bool
Operator overload for godot.Vector2
< godot.Vector2
.
staticinlineop_LessThanOrEqual(left:Vector2, right:Vector2):Bool
Operator overload for godot.Vector2
<= godot.Vector2
.
staticinlineop_Modulus(vec:Vector2, divisor:Float):Vector2
staticinlineop_Modulus(vec:Vector2, divisorv:Vector2):Vector2
Operator overload for godot.Vector2
% ((global::System.Single)(Float
)).
staticinlineop_Multiply(vec:Vector2, scale:Float):Vector2
staticinlineop_Multiply(left:Vector2, right:Vector2):Vector2
staticinlineop_Multiply(scale:Float, vec:Vector2):Vector2
Operator overload for godot.Vector2
* ((global::System.Single)(Float
)).
staticinlineop_Subtraction(left:Vector2, right:Vector2):Vector2
Operator overload for godot.Vector2
- godot.Vector2
.
Constructor
new(x:Single = 0, y:Single = 0)
new(v:Vector2)
Constructs a new godot.Vector2
with the given components.
Parameters:
x | The vector's X component. |
---|---|
y | The vector's Y component. |
Variables
Methods
abs():Vector2
Returns a new vector with all components in absolute values (i.e. positive).
Returns:
A vector with godot.Mathf.abs
called on each component.
angle():Single
Returns this vector's angle with respect to the X axis, or (1, 0) vector, in radians.
Equivalent to the result of godot.Mathf.atan2
when
called with the vector's godot.Vector2.y
and godot.Vector2.x
as parameters: Mathf.Atan2(v.y, v.x)
.
Returns:
The angle of this vector, in radians.
angleTo(to:Vector2):Single
Returns the angle to the given vector, in radians.
Parameters:
to | The other vector to compare this vector to. |
---|
Returns:
The angle between the two vectors, in radians.
angleToPoint(to:Vector2):Single
Returns the angle between the line connecting the two points and the X axis, in radians.
Parameters:
to | The other vector to compare this vector to. |
---|
Returns:
The angle between the two vectors, in radians.
aspect():Single
Returns the aspect ratio of this vector, the ratio of godot.Vector2.x
to godot.Vector2.y
.
Returns:
The godot.Vector2.x
component divided by the godot.Vector2.y
component.
bounce(normal:Vector2):Vector2
Returns the vector "bounced off" from a plane defined by the given normal.
Parameters:
normal | The normal vector defining the plane to bounce off. Must be normalized. |
---|
Returns:
The bounced vector.
ceil():Vector2
Returns a new vector with all components rounded up (towards positive infinity).
Returns:
A vector with godot.Mathf.ceil
called on each component.
clamped(length:Single):Vector2
Returns the vector with a maximum length by limiting its length to length
.
Parameters:
length | The length to limit to. |
---|
Returns:
The vector with its length limited.
cross(b:Vector2):Single
Returns the cross product of this vector and b
.
Parameters:
b | The other vector. |
---|
Returns:
The cross product value.
cubicInterpolate(b:Vector2, preA:Vector2, postB:Vector2, weight:Single):Vector2
Performs a cubic interpolation between vectors preA
, this vector,
b
, and postB
, by the given amount weight
.
Parameters:
b | The destination vector. |
---|---|
preA | A vector before this vector. |
postB | A vector after |
weight | A value on the range of 0.0 to 1.0, representing the amount of interpolation. |
Returns:
The interpolated vector.
directionTo(b:Vector2):Vector2
Returns the normalized vector pointing from this vector to b
.
Parameters:
b | The other vector to point towards. |
---|
Returns:
The direction from this vector to b
.
distanceSquaredTo(to:Vector2):Single
Returns the squared distance between this vector and to
.
This method runs faster than godot.Vector2.distanceTo
, so prefer it if
you need to compare vectors or need the squared distance for some formula.
Parameters:
to | The other vector to use. |
---|
Returns:
The squared distance between the two vectors.
distanceTo(to:Vector2):Single
Returns the distance between this vector and to
.
Parameters:
to | The other vector to use. |
---|
Returns:
The distance between the two vectors.
dot(with:Vector2):Single
Returns the dot product of this vector and with
.
Parameters:
with | The other vector to use. |
---|
Returns:
The dot product of the two vectors.
floor():Vector2
Returns a new vector with all components rounded down (towards negative infinity).
Returns:
A vector with godot.Mathf.floor
called on each component.
inverse():Vector2
Returns the inverse of this vector. This is the same as new Vector2(1 / v.x, 1 / v.y)
.
Returns:
The inverse of this vector.
isEqualApprox(other:Vector2):Bool
Returns true
if this vector and other
are approximately equal,
by running godot.Mathf.isEqualApprox
on each component.
Parameters:
other | The other vector to compare. |
---|
Returns:
Whether or not the vectors are approximately equal.
isNormalized():Bool
Returns true
if the vector is normalized, and false
otherwise.
Returns:
A bool
indicating whether or not the vector is normalized.
length():Single
Returns the length (magnitude) of this vector.
Returns:
The length of this vector.
See also:
lengthSquared():Single
Returns the squared length (squared magnitude) of this vector.
This method runs faster than godot.Vector2.length
, so prefer it if
you need to compare vectors or need the squared length for some formula.
Returns:
The squared length of this vector.
linearInterpolate(to:Vector2, weight:Single):Vector2
LinearInterpolate(to:Vector2, weight:Vector2):Vector2
Returns the result of the linear interpolation between
this vector and to
by amount weight
.
Parameters:
to | The destination vector for interpolation. |
---|---|
weight | A value on the range of 0.0 to 1.0, representing the amount of interpolation. |
Returns:
The resulting vector of the interpolation.
maxAxis():Vector2_Axis
Returns the axis of the vector's largest value. See godot.Vector2_Axis
.
If both components are equal, this method returns godot.Vector2_Axis.x
.
Returns:
The index of the largest axis.
minAxis():Vector2_Axis
Returns the axis of the vector's smallest value. See godot.Vector2_Axis
.
If both components are equal, this method returns godot.Vector2_Axis.y
.
Returns:
The index of the smallest axis.
moveToward(to:Vector2, delta:Single):Vector2
Moves this vector toward to
by the fixed delta
amount.
Parameters:
to | The vector to move towards. |
---|---|
delta | The amount to move towards by. |
Returns:
The resulting vector.
normalized():Vector2
Returns the vector scaled to unit length. Equivalent to v / v.Length()
.
Returns:
A normalized version of the vector.
perpendicular():Vector2
Returns a perpendicular vector rotated 90 degrees counter-clockwise compared to the original, with the same length.
Returns:
The perpendicular vector.
posMod(mod:Single):Vector2
PosMod(modv:Vector2):Vector2
Returns a vector composed of the godot.Mathf.posMod
of this vector's components
and mod
.
Parameters:
mod | A value representing the divisor of the operation. |
---|
Returns:
A vector with each component godot.Mathf.posMod
by mod
.
project(onNormal:Vector2):Vector2
Returns this vector projected onto another vector onNormal
.
Parameters:
onNormal | The vector to project onto. |
---|
Returns:
The projected vector.
reflect(normal:Vector2):Vector2
Returns this vector reflected from a plane defined by the given normal
.
Parameters:
normal | The normal vector defining the plane to reflect from. Must be normalized. |
---|
Returns:
The reflected vector.
rotated(phi:Single):Vector2
Rotates this vector by phi
radians.
Parameters:
phi | The angle to rotate by, in radians. |
---|
Returns:
The rotated vector.
round():Vector2
Returns this vector with all components rounded to the nearest integer, with halfway cases rounded towards the nearest multiple of two.
Returns:
The rounded vector.
sign():Vector2
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 godot.Mathf.sign
on each component.
Returns:
A vector with all components as either 1
, -1
, or 0
.
slerp(to:Vector2, weight:Single):Vector2
Returns the result of the spherical linear interpolation between
this vector and to
by amount weight
.
Note: Both vectors must be normalized.
Parameters:
to | The destination vector for interpolation. Must be normalized. |
---|---|
weight | A value on the range of 0.0 to 1.0, representing the amount of interpolation. |
Returns:
The resulting vector of the interpolation.
slide(normal:Vector2):Vector2
Returns this vector slid along a plane defined by the given normal
.
Parameters:
normal | The normal vector defining the plane to slide on. |
---|
Returns:
The slid vector.
snapped(step:Vector2):Vector2
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.
Parameters:
step | A vector value representing the step size to snap to. |
---|
Returns:
The snapped vector.
tangent():Vector2
Returns a perpendicular vector rotated 90 degrees counter-clockwise
compared to the original, with the same length.
Deprecated, will be replaced by godot.Vector2.perpendicular
in 4.0.
Returns:
The perpendicular vector.