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
| Signature | Description |
|---|---|
Vector3.new(x, y, z) | Returns a new Vector3 with the given components. |
Vector3.new() | Returns a new Vector3 initialised to (0, 0, 0). |
Instance Properties
| Property | Type | Read-only | Description |
|---|---|---|---|
x | number | No | The X component. |
y | number | No | The Y component. |
z | number | No | The Z component. |
magnitude | number | Yes | The length of the vector. |
sqrMagnitude | number | Yes | The squared length (cheaper than magnitude when exact length is not needed). |
normalized | Vector3 | Yes | A unit-length copy of the vector. Does not mutate the original. |
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.| Constant | Value |
|---|---|
Vector3.zero | (0, 0, 0) |
Vector3.one | (1, 1, 1) |
Vector3.forward | (0, 0, 1) |
Vector3.back | (0, 0, -1) |
Vector3.up | (0, 1, 0) |
Vector3.down | (0, -1, 0) |
Vector3.left | (-1, 0, 0) |
Vector3.right | (1, 0, 0) |
Vector3.positiveInfinity | (∞, ∞, ∞) |
Vector3.negativeInfinity | (-∞, -∞, -∞) |
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
| Property | Type | Description |
|---|---|---|
face | Face | The face enum value. |
faceName | string | The name of the face. |
orientation | Orientation | The orientation enum value. |
orientationName | string | The name of the orientation. |
front, back, right, left, up, down | Vector3 | Direction vectors relative to the basis. |
turnUp, turnDown, turnLeft, turnRight, turnBack | Basis | Adjacent bases reached by turning in that direction. |