Types
Vectors
Vector2 and Vector3 constructors, properties, operators and methods.
Vector2
Vector2.new(x = 0, y = 0)
Creates a vector with fields X and Y.
Properties
| Property | Meaning |
|---|---|
X, Y | The components |
Magnitude | Length |
Unit | A vector of length 1 in the same direction. (0, 0) stays (0, 0) |
Operators
| Expression | Result |
|---|---|
a + b, a - b | Component-wise |
a * b | Component-wise, or scaling when one side is a number |
a / b | Component-wise, or division when b is a number |
-a | Negation |
a == b | true when both components are equal |
tostring(a) | Text like 10, 20 |
Methods
a:Dot(b)
Dot product.
a:Lerp(b, t)
Linear interpolation from a to b. t = 0 gives a, t = 1 gives b.
Vector3
Vector3.new(x = 0, y = 0, z = 0)
Creates a vector with fields X, Y and Z.
Properties
Same as Vector2, with Z added.
Operators
Same as Vector2. tostring gives x, y, z.
Methods
a:Dot(b)
Dot product.
a:Cross(b)
Cross product.
a:Lerp(b, t)
Linear interpolation.
a:Distance(b)
Distance between the two points.
local a = Vector3.new(0, 0, 0)
local b = Vector3.new(3, 4, 0)
print((b - a).Magnitude) -- 5
print(a:Distance(b)) -- 5
print(a:Lerp(b, 0.5)) -- 1.5, 2, 0
print((b * 2).Unit) -- 0.6, 0.8, 0