Vector3
3D positions, directions, and velocities, with the axis and zero vectors alongside
Constructors
6 members Access: shared
- new
(x: number, y: number, z: number) -> vector make a vector
Parameters
Name Type Description x number Component along the X axis in studs. y number Component along the Y axis in studs. z number Component along the Z axis in studs. returns vector — - one:
vector the all-ones vector
- xAxis:
vector the x axis
- yAxis:
vector the y axis
- zAxis:
vector the z axis
- zero:
vector the zero vector
3D Vector Math and Distances
Lifecycle: Shared
Subtraction, .Magnitude, and .Unit cover most distance and direction work.
Luau
local startPos = Vector3.new(0, 10, 0)local targetPos = Vector3.new(12, 10, 16)local displacement = targetPos - startPoslocal distance = displacement.Magnitudelocal direction = displacement.Unitprint(string.format("Distance: %.2f, Direction: %s", distance, tostring(direction)))