Vec2:

A 2D vector.

x: number

The x coordinate

y: number

The y coordinate

fromAngle(deg: number): Vec2

Create a new Vec2 from an angle in degrees

fromArray(arr: Array): Vec2

Create a new Vec2 from an array

ZERO: Vec2

An empty vector. (0, 0)

ONE: Vec2

A vector with both components of 1. (1, 1)

LEFT: Vec2

A vector signaling to the left. (-1, 0)

RIGHT: Vec2

A vector signaling to the right. (1, 0)

UP: Vec2

A vector signaling up. (0, -1)

DOWN: Vec2

A vector signaling down. (0, 1)

clone(): Vec2

Clone the vector

add(args: Vec2Args): Vec2

Returns the addition with another vector.

sub(args: Vec2Args): Vec2

Returns the subtraction with another vector.

scale(args: Vec2Args): Vec2

Scale by another vector. or a single number

dist(args: Vec2Args): number

Get distance between another vector

sdist(args: Vec2Args): number

Get squared distance between another vector

sdist(v: Vec2, other: Vec2): number

Calculates the squared distance between the vectors

paramvThe vector

paramotherThe other vector

returnsThe distance between the vectors

len(): number

Get length of the vector

sincev3000.0

slen(): number

Get squared length of the vector

sincev3000.0

unit(): Vec2

Get the unit vector (length of 1).

normal(): Vec2

Get the perpendicular vector.

reflect(normal: Vec2): Vec2

Get the reflection of a vector with a normal.

sincev3000.0

project(on: Vec2): Vec2

Get the projection of a vector onto another vector.

sincev3000.0

reject(on: Vec2): Vec2

Get the rejection of a vector onto another vector.

sincev3000.0

dot(p2: Vec2): number

Get the dot product with another vector.

dot(v: Vec2, other: Vec2): number

Get the dot product between 2 vectors.

sincev3000.0

cross(p2: Vec2): number

Get the cross product with another vector.

sincev3000.0

cross(v: Vec2, other: Vec2): number

Get the cross product between 2 vectors.

sincev3000.0

angle(args: Vec2Args): number

Get the angle of the vector in degrees.

angleBetween(args: Vec2Args): number

Get the angle between this vector and another vector.

sincev3000.0

lerp(dest: Vec2, t: number): Vec2

Linear interpolate to a destination vector (for positions).

slerp(dest: Vec2, t: number): Vec2

Spherical linear interpolate to a destination vector (for rotations).

sincev3000.0

isZero(): boolean

If the vector (x, y) is zero.

sincev3000.0

toFixed(n: number): Vec2

To n precision floating point.

transform(m: Mat4): Vec2

Multiply by a Mat4.

sincev3000.0

eq(other: Vec2): boolean

See if one vector is equal to another.

sincev3000.0

bbox(): Rect

Converts the vector to a Rect with the vector as the origin.

sincev3000.0.

toArray(): Array<number>

Converts the vector to an array.

sincev3001.0