Skip to content

Vector3

Global · Vector3 · server and client scripts

Vector3 creates 3D vectors for positions, directions and sizes, in units. A vector is a Luau vector: read X, Y and Z, its length as Magnitude and its direction as Unit, and call :Dot, :Cross and :Lerp with a colon. Arithmetic works one component at a time, and * and / also scale by a number. Luau's vector library works on these values too; read Unit rather than vector.normalize when a vector can be zero, because Vector3.Zero.Unit is Vector3.Zero while vector.normalize(Vector3.Zero) is NaN.

Example

-- Server script in a part.
local offset = Vector3.new(3, 0, 4)
print(offset.Magnitude) -- prints 5
print(offset:Dot(Vector3.XAxis)) -- prints 3
local pos = self.Position
if pos then
    self.Position = pos + offset.Unit * 10
end

new

Function
new(x: number?, y: number?, z: number?) -> vector

Vector3.new creates a vector from x, y and z.

Example

-- Server script in a part.
self.Position = Vector3.new(0, 10, 0)

Zero

PropertyRead only
Zero: vector

Vector3.Zero is the vector with every component 0.

Default Vector3.new(0, 0, 0)

One

PropertyRead only
One: vector

Vector3.One is the vector with every component 1.

Default Vector3.new(1, 1, 1)

XAxis

PropertyRead only
XAxis: vector

Vector3.XAxis is the unit vector along +X.

Default Vector3.new(1, 0, 0)

YAxis

PropertyRead only
YAxis: vector

Vector3.YAxis is the unit vector along +Y, which points up.

Default Vector3.new(0, 1, 0)

ZAxis

PropertyRead only
ZAxis: vector

Vector3.ZAxis is the unit vector along +Z.

Default Vector3.new(0, 0, 1)