Math
CompilesThe $math natives cover what the operators don’t. Positions and directions are vec3, and z is up.
Distance between two points
Section titled “Distance between two points”let a: vec3 = vec3(0, 0, 0)let b: vec3 = vec3(300, 400, 0)let far: float = $math.distance(a, b)let close_enough: bool = far < 500.0Direction from one point to another
Section titled “Direction from one point to another”let from: vec3 = vec3(0, 0, 0)let to: vec3 = vec3(10, 0, 0)let direction: vec3 = $math.normalize(to - from)normalize makes a vector length 1, so it’s pure direction.
Blend between two values
Section titled “Blend between two values”$math.lerp(a, b, t) gives a when t is 0, b when t is 1, and in between for anything between:
let halfway: float = $math.lerp(0.0, 100.0, 0.5)let spot: vec3 = $math.lerp(vec3(0, 0, 0), vec3(0, 0, 200), 0.25)Keep a value in range
Section titled “Keep a value in range”let requested: float = 140.0let volume: float = $math.clamp(requested, 0.0, 100.0)let fraction: float = $math.saturate(1.4) // clamp to 0..1Map one range onto another
Section titled “Map one range onto another”Turn a distance of 0–1000 into a strength of 1–0:
let distance: float = 250.0let strength: float = $math.map_range(0.0, 1000.0, 1.0, 0.0, distance)Random numbers
Section titled “Random numbers”let roll: int = $math.randi(1, 6) // 1 to 6, both includedlet jitter: float = $math.randf(-5.0, 5.0)Angles
Section titled “Angles”The engine works in radians. Convert, and build or read rotations:
let radians: float = $math.deg2rad(90.0)let turned: vec4 = $math.rotation_from_axis_angle(vec3(0, 0, 1), radians)let angles: vec3 = $math.eulers_from_rotation(turned)let yaw: float = angles.zeulers_from_rotation gives roll, pitch and yaw as x, y and z.
Waves (sin, cos), rounding (floori, ceili, roundi), min, max, abs, dot, cross, slerp for
rotations: see the math reference.