Vector3

Vector3 is a fundamental datatype for representing positions, directions, and sizes in 3D space. It supports common vector operations including arithmetic, magnitude calculation, normalization, and interpolation.

Properties

X

number

The x-coordinate of the vector

Y

number

The y-coordinate of the vector

Z

number

The z-coordinate of the vector

Methods

Magnitude()

number

The length of the vector

local vec = Vector3.new(3, 4, 0)
print(vec.Magnitude) -- 5

Unit()

Vector3

A normalized copy of the vector with magnitude of 1

local vec = Vector3.new(10, 0, 0)
local unit = vec.Unit
print(unit.Magnitude) -- 1

Abs()

Vector3

Returns a Vector3 with the absolute value of each component

local vec = Vector3.new(-5, -10, 3)
local abs = vec:Abs() -- Vector3(5, 10, 3)

Ceil()

Vector3

Returns a Vector3 with each component rounded up to the nearest integer

local vec = Vector3.new(1.2, 2.7, 3.1)
local ceiled = vec:Ceil() -- Vector3(2, 3, 4)

Floor()

Vector3

Returns a Vector3 with each component rounded down to the nearest integer

local vec = Vector3.new(1.8, 2.3, 3.9)
local floored = vec:Floor() -- Vector3(1, 2, 3)

Dot(v: Vector3)

number

Returns the dot product of this vector and another vector

Parameters:

  • v Vector3 - The other vector
local a = Vector3.new(1, 0, 0)
local b = Vector3.new(0, 1, 0)
print(a:Dot(b)) -- 0 (perpendicular)

Cross(v: Vector3)

Vector3

Returns the cross product of this vector and another vector

Parameters:

  • v Vector3 - The other vector
local a = Vector3.xAxis
local b = Vector3.yAxis
local cross = a:Cross(b) -- Returns Vector3.zAxis

Lerp(goal: Vector3, alpha: number)

Vector3

Returns a Vector3 linearly interpolated between this vector and the goal

Parameters:

  • goal Vector3 - The target vector to interpolate towards
  • alpha number - The interpolation factor (0-1)
local start = Vector3.new(0, 0, 0)
local finish = Vector3.new(10, 10, 10)
local mid = start:Lerp(finish, 0.5) -- Vector3(5, 5, 5)

FuzzyEq(v: Vector3)

bool

Returns true if the magnitudes of both vectors are approximately equal within epsilon

Parameters:

  • v Vector3 - The other vector to compare
local a = Vector3.new(1, 0, 0)
local b = Vector3.new(0.99999, 0, 0)
print(a:FuzzyEq(b)) -- true