Vector4
The Vector4 class represents a four-dimensional vector with components x, y, z, and w, providing methods for common vector operations.
Usage
To use this class, add the following require at the top of your script:
Reference
Operators
+
Component-wise addition
-
Unary minus (negation)
*
Multiply vector by scalar
/
Divide vector by scalar
==
Approximate equality (delta \< 1e-10)
tostring
String representation "[x,y,z,w]"
new
Create new vector
Parameters
x(number): x componenty(number): y componentz(number): z componentw(number): w component
Returns
Vector4: vector
set
Set components of the vector
Parameters
x(number): x componenty(number): y componentz(number): z componentw(number): w component
get
Return the 4 components as array
Returns
array: 4 components
toData
Get values of vector
Returns
table: values
lerp
Linear interpolation between 2 vectors
Parameters
from(Vector4): first vectorto(Vector4): second vectort(number): position between those vectors from 0 to 1
Returns
Vector4: vector
moveTowards
Move one vector in the direction of the target vector
Parameters
current(Vector4): current positiontarget(Vector4): target positionmaxDistanceDelta(number): maximum distance to move towards target
Returns
Vector4: a new vector
scaled
Scale vector by another vector
Parameters
scale(Vector4): scale vector
Returns
Vector4: scaled vector
scale
Scale this vector by another vector
Parameters
scale(Vector4): scale vector
Returns
Vector4: itself
normalized
Return normalized version of this vector
Returns
Vector4: vector
normalize
Normalize this vector
Returns
Vector4: itself
div
Devide this vector by a number
Parameters
d(number): scalar value
Returns
Vector4: itself
mul
Multiply this vector with a number
Parameters
d(number): scalar value
Returns
Vector4: itself
add
Add another vector to this vector
Parameters
b(Vector4): other vector
Returns
Vector4: itself
sub
Subtract another vector from this one
Parameters
b(Vector4): other vector
Returns
Vector4: itself
dot
Calculates dot product from 2 vectors
Parameters
a(Vector4): first vectorb(Vector4): second vector
Returns
number: dot product
project
Project one vector onto another
Parameters
a(Vector4): first vectorb(Vector4): second vector
Returns
Vector4: vector
distance
Calculate distance between 2 vectors
Parameters
a(Vector4): first vectorb(Vector4): second vector
Returns
number
magnitude
Calculate magnitude of the vector
Returns
number
sqrMagnitude
Calculate squared magnitude of the vector
Returns
number: magnitude
min
Return the minimum of all components of two vectors into a new vector
Parameters
lhs(Vector4): first vectorrhs(Vector4): second vector
Returns
Vector4: vector
max
Return the maximum of all components of two vectors into a new vector
Parameters
lhs(Vector4): first vectorrhs(Vector4): second vector
Returns
Vector4: vector