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
numberThe x-coordinate of the vector
Y
numberThe y-coordinate of the vector
Z
numberThe z-coordinate of the vector
Methods
Magnitude()
numberThe length of the vector
local vec = Vector3.new(3, 4, 0)
print(vec.Magnitude) -- 5
Unit()
Vector3A 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()
Vector3Returns 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()
Vector3Returns 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()
Vector3Returns 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)
numberReturns the dot product of this vector and another vector
Parameters:
vVector3 - The other vector
local a = Vector3.new(1, 0, 0)
local b = Vector3.new(0, 1, 0)
print(a:Dot(b)) -- 0 (perpendicular)
Returns the cross product of this vector and another vector
Parameters:
vVector3 - The other vector
local a = Vector3.xAxis
local b = Vector3.yAxis
local cross = a:Cross(b) -- Returns Vector3.zAxis
Returns a Vector3 linearly interpolated between this vector and the goal
Parameters:
goalVector3 - The target vector to interpolate towardsalphanumber - 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)
boolReturns true if the magnitudes of both vectors are approximately equal within epsilon
Parameters:
vVector3 - 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