Skip to main content
The Vector3 class represents a point or direction in 3D space with three floating-point components: x, y, and z. You use it everywhere positions, velocities, and directions are needed — passing it to transform properties, computing distances between objects, or blending between two locations with lerp. A companion class, Basis, builds on Vector3 to describe the full orientation of a face in the game world; a brief reference for Basis appears at the end of this page.

Constructors


Instance Properties

You can also index a Vector3 by integer position (v[1] → x, v[2] → y, v[3] → z) for read and write access.

Static Constants

These read-only class-level vectors cover the most common directions and sentinel values.

Instance Methods

copy

Returns a new Vector3 with the same component values as the original.

set

Mutates the vector in place, assigning new values to all three components.

normalize

Normalises the vector in place so that its magnitude becomes 1. To get a normalised copy without modifying the original, read the normalized property instead.

Static Methods

dot

Returns the dot product of two vectors — useful for checking alignment between directions.

cross

Returns a vector perpendicular to both inputs.

distance

Returns the Euclidean distance between two points.

lerp

Linearly interpolates between a and b by the clamped factor t (0 → a, 1 → b).

lerpUnclamped

Same as lerp but t is not clamped, so values outside [0, 1] extrapolate beyond the endpoints.

slerp

Spherically interpolates between two direction vectors, preserving arc length.

slerpUnclamped

Unclamped variant of slerp.

scale

Returns a component-wise product of two vectors (i.e. (a.x*b.x, a.y*b.y, a.z*b.z)). Also available as an instance method that scales the vector in place using a single Vector3 argument.

moveTowards

Moves current toward target by at most maxDistanceDelta units.

rotateTowards

Rotates current toward target by at most maxRadiansDelta radians, also clamping the magnitude change.

smoothDamp

Gradually moves current toward target in a spring-damper fashion. currentVelocity is updated each frame. maxSpeed and deltaTime are optional.

reflect

Reflects inDirection off a surface with the given inNormal.

project

Projects vector onto the direction onNormal.

projectOnPlane

Removes the component of vector that is parallel to planeNormal, returning the flat component.

angle

Returns the unsigned angle in degrees between from and to.

signedAngle

Returns the signed angle in degrees from from to to, measured around axis.

clampMagnitude

Returns a copy of vector whose length is clamped to maxLength.

min / max

Return component-wise minimum or maximum of two vectors.

orthoNormalize

Orthonormalises the normal and tangent vectors (and optionally binormal) in place using Gram-Schmidt.

Usage Examples

Setting a world position

Calculating distance between two objects

Smoothly moving toward a target


The Basis Class

Basis describes the orientation of a tile face in 3D space. You will typically receive a Basis from the engine rather than constructing one yourself. Constructors
Read-only properties Methods