Skip to main content
Vector2 is a 2D vector with x, y components. You’ll encounter it primarily as the return type of Math.worldToScreen - screen-space pixel coordinates for ESP overlays and HUD elements.
Unlike Vector, Vector2 has no z component. Operations like mul and div accept both a scalar number and another Vector2 - check the overloads below.

Overview

Creating vectors

Numbers, arrays, objects, or axis presets.

Arithmetic

Add, subtract, multiply, divide - all return new instances.

Length & distance

Magnitude and distance on the 2D plane.

Products

Dot product, 2D cross product.

Transforms

Normalize, rotate, absolute value.

Utility

Clone, convert to array, string output.

Properties


Creating vectors

Constructor


Creates a new Vector2. Missing components default to 0.

Vector2.zero


Returns a new (0, 0) vector.

Vector2.one


Returns a new (1, 1) vector.

Vector2.xAxis


Returns (1, 0) - the horizontal unit vector.

Vector2.yAxis


Returns (0, 1) - the vertical unit vector.

Arithmetic

All arithmetic methods return a new Vector2.

add


Component-wise addition.

sub


Component-wise subtraction.

mul


Overloaded - accepts a scalar or a Vector2 for component-wise multiplication.

div


Overloaded - accepts a scalar or a Vector2 for component-wise division.

Length & distance

length


Returns the 2D Euclidean length: √(x² + y²).

lengthSqr


Returns the squared length: x² + y². Faster for comparisons.

distTo


Returns the distance to another Vector2.

Products

dot


Returns the 2D dot product: x*ox + y*oy.

cross


Returns the 2D cross product - a scalar, not a vector. Its sign tells you the winding direction: positive = other is counter-clockwise from vec, negative = clockwise.
In 3D the cross product returns a vector. In 2D it returns a scalar - the z-component of what the 3D cross would be. This is different from Vector.cross.

Transforms

normalize


Scales to length 1 in place. Returns this.
Mutates the original. Use normalized() if you need the original preserved.

normalized


Returns a new unit vector. The original is untouched.

rotate


Rotates the vector by degrees around the origin. Returns a new Vector2. Positive = counter-clockwise.

abs


Returns a new Vector2 with absolute values of both components.

Utility

clone


Returns an independent deep copy.

toArray


Returns [x, y] as a plain array.

toString


Returns a human-readable string with 3 decimal places.

Common patterns