Skip to content

vec3

3D vector used for world coordinates: positions, raycasts, blocks, projection and the 3D renderer.

local pos = player:position()
local above = pos + vec3(0, 2, 0)
local eye = player:eye_position()
local hit = world:raycast(eye, eye + player:velocity() * 20)

Construction

vec3(x?, y?, z?) builds one; missing components default to 0. A vec3 is a plain table with x, y, z fields — read and write them directly. Any table with numeric x/y/z is accepted where a vec3 is expected.

Arithmetic

+, -, *, / work componentwise with another vector or uniformly with a number (v * 2, 2 * v). Unary - negates, == compares components, tostring(v) prints vec3(x, y, z). Every operation returns a new vector.

Methods

Method What it does
v:length() Length
v:length_sq() Squared length (cheaper for comparisons)
v:distance(u) Distance to another vector
v:distance_sq(u) Squared distance
v:normalized() Unit-length copy
v:dot(u) Dot product
v:cross(u) Cross product
v:lerp(u, t) Linear interpolation (t = 0v, t = 1u)
v:floor() Componentwise math.floor — block position
v:copy() Independent copy
v:unpack() Components as three return values
local target = enemy:position():lerp(enemy:position() + enemy:velocity(), client.tick_delta())
rotation.look_at(target + vec3(0, enemy:height() / 2, 0))
Navigation

Type to search…

↑↓ navigate↵ selectEsc close