2-element structure that can be used to represent positions in 2D space or any other pair of numeric values.

Static variables

@:native("Down")staticread onlyDOWN:Vector2

Down unit vector. Y is down in 2D, so this vector points +Y.

Value: Equivalent to new Vector2(0, 1).

@:native("Inf")staticread onlyINF:Vector2

Infinity vector, a vector with all components set to godot.Mathf.INF.

Value: Equivalent to new Vector2(Mathf.Inf, Mathf.Inf).

@:native("Left")staticread onlyLEFT:Vector2

Left unit vector. Represents the direction of left.

Value: Equivalent to new Vector2(-1, 0).

@:native("NegOne")staticread onlyNEG_ONE:Vector2

Deprecated, please use a negative sign with godot.Vector2.one instead.

Value: Equivalent to new Vector2(-1, -1).

@:native("One")staticread onlyONE:Vector2

One vector, a vector with all components set to 1.

Value: Equivalent to new Vector2(1, 1).

@:native("Right")staticread onlyRIGHT:Vector2

Right unit vector. Represents the direction of right.

Value: Equivalent to new Vector2(1, 0).

@:native("Up")staticread onlyUP:Vector2

Up unit vector. Y is down in 2D, so this vector points -Y.

Value: Equivalent to new Vector2(0, -1).

@:native("Zero")staticread onlyZERO:Vector2

Zero vector, a vector with all components set to 0.

Value: Equivalent to new Vector2(0, 0).

Static methods

@:op(A + B)staticinlineop_Addition(left:Vector2, right:Vector2):Vector2

Operator overload for godot.Vector2 + godot.Vector2.

@:op(A / B)staticinlineop_Division(vec:Vector2, divisor:Float):Vector2

@:op(A / B)staticinlineop_Division(vec:Vector2, divisorv:Vector2):Vector2

Operator overload for godot.Vector2 / ((global::System.Single)(Float)).

@:op(A == B)staticinlineop_Equality(left:Vector2, right:Vector2):Bool

Operator overload for godot.Vector2 == godot.Vector2.

@:op(A > B)staticinlineop_GreaterThan(left:Vector2, right:Vector2):Bool

Operator overload for godot.Vector2 > godot.Vector2.

@:op(A >= B)staticinlineop_GreaterThanOrEqual(left:Vector2, right:Vector2):Bool

Operator overload for godot.Vector2 >= godot.Vector2.

@:op(A != B)staticinlineop_Inequality(left:Vector2, right:Vector2):Bool

Operator overload for godot.Vector2 != godot.Vector2.

@:op(A < B)staticinlineop_LessThan(left:Vector2, right:Vector2):Bool

Operator overload for godot.Vector2 < godot.Vector2.

@:op(A <= B)staticinlineop_LessThanOrEqual(left:Vector2, right:Vector2):Bool

Operator overload for godot.Vector2 <= godot.Vector2.

@:op(A % B)staticinlineop_Modulus(vec:Vector2, divisor:Float):Vector2

@:op(A % B)staticinlineop_Modulus(vec:Vector2, divisorv:Vector2):Vector2

Operator overload for godot.Vector2 % ((global::System.Single)(Float)).

@:op(A * B)staticinlineop_Multiply(vec:Vector2, scale:Float):Vector2

@:op(A * B)staticinlineop_Multiply(left:Vector2, right:Vector2):Vector2

@:op(A * B)staticinlineop_Multiply(scale:Float, vec:Vector2):Vector2

Operator overload for godot.Vector2 * ((global::System.Single)(Float)).

@:op(A - B)staticinlineop_Subtraction(left:Vector2, right:Vector2):Vector2

Operator overload for godot.Vector2 - godot.Vector2.

@:op(-A)staticinlineop_UnaryNegation(vec:Vector2):Vector2

Operator overload for -godot.Vector2.

Constructor

@:value({ y : 0, x : 0 })@:native("new")new(x:Single = 0, y:Single = 0)

@:native("new")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

@:native("x")x:Single

The vector's X component. Also accessible by using the index position [0].

@:native("y")y:Single

The vector's Y component. Also accessible by using the index position [1].

Methods

@:native("Abs")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.

@:native("Angle")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.

@:native("AngleTo")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.

@:native("AngleToPoint")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.

@:native("Aspect")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.

@:native("Bounce")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.

@:native("Ceil")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.

@:native("Clamped")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.

@:native("Cross")cross(b:Vector2):Single

Returns the cross product of this vector and b.

Parameters:

b

The other vector.

Returns:

The cross product value.

@:native("CubicInterpolate")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 b.

weight

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns:

The interpolated vector.

@:native("DirectionTo")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.

@:native("DistanceSquaredTo")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.

@:native("DistanceTo")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.

@:native("Dot")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.

@:native("Floor")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.

@:native("Inverse")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.

@:native("IsEqualApprox")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.

@:native("IsNormalized")isNormalized():Bool

Returns true if the vector is normalized, and false otherwise.

Returns:

A bool indicating whether or not the vector is normalized.

@:native("Length")length():Single

Returns the length (magnitude) of this vector.

Returns:

The length of this vector.

See also:

@:native("LengthSquared")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.

@:native("LinearInterpolate")linearInterpolate(to:Vector2, weight:Single):Vector2

@:native("LinearInterpolate")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.

@:native("MaxAxis")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.

@:native("MinAxis")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.

@:native("MoveToward")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.

@:native("Normalized")normalized():Vector2

Returns the vector scaled to unit length. Equivalent to v / v.Length().

Returns:

A normalized version of the vector.

@:native("Perpendicular")perpendicular():Vector2

Returns a perpendicular vector rotated 90 degrees counter-clockwise compared to the original, with the same length.

Returns:

The perpendicular vector.

@:native("PosMod")posMod(mod:Single):Vector2

@:native("PosMod")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.

@:native("Project")project(onNormal:Vector2):Vector2

Returns this vector projected onto another vector onNormal.

Parameters:

onNormal

The vector to project onto.

Returns:

The projected vector.

@:native("Reflect")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.

@:native("Rotated")rotated(phi:Single):Vector2

Rotates this vector by phi radians.

Parameters:

phi

The angle to rotate by, in radians.

Returns:

The rotated vector.

@:native("Round")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.

@:native("Set")set(x:Single, y:Single):Void

@:native("Set")Set(v:Vector2):Void

@:native("Sign")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.

@:native("Slerp")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.

@:native("Slide")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.

@:native("Snapped")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.

@:native("Tangent")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.

@:native("ToString")toString():String

@:native("ToString")ToString(format:String):String

Converts this godot.Vector2 to a string.

Returns:

A string representation of this vector.