Vector2 methods
Unit vector, interpolation, dot and cross products, plus operators.
Syntax
v.Unit -> Vector2
v:Lerp(other: Vector2, alpha: number) -> Vector2
v:Dot(other: Vector2) -> number
v:Cross(other: Vector2) -> number
-v -> Vector2
v == other -> boolean
Parameters
| Parameter | Type | Description |
|---|---|---|
other | Vector2 | Second operand. |
alpha | number | 0 returns v, 1 the target. |
Returns
| Type | Description |
|---|---|
Vector2 | number | boolean | Unit, Lerp and unary minus return Vector2; Dot/Cross return numbers. |
Description
Dot is x1*x2 + y1*y2; Cross returns the scalar z component, x1*y2 - y1*x2.
Unit normalizes and falls back to (0, 0) for a zero-length vector.
The + - * / operators and .Magnitude remain available as before.
Example
local a = Vector2.new(3, 4)
print(a.Magnitude, a.Unit) -- 5, 0.6 0.8
print(a:Dot(Vector2.new(1, 0))) -- 3
print(a:Cross(Vector2.new(0, 1))) -- 3
print(-a, a == Vector2.new(3, 4))
Notes
Vector2 == Vector2— Compares both components exactly.