Vectors - BenBerke/Tilky-Engine GitHub Wiki
Lua Vector Bindings
The engine exposes Vector2, Vector3, and Vector4 types to Lua using sol2. These types are fully constructible in scripts and provide direct access to their components and common math properties.
Vector2
Construction
local v = Vector2()
local v = Vector2(x, y)
Fields
| Name | Type |
|---|---|
| x | number |
| y | number |
You can read and write these directly:
v.x = 10
v.y = 20
Properties
length
local len = v.length
Returns the magnitude of the vector.
lengthSquared
local len2 = v.lengthSquared
Returns squared length (faster than length).
normalized
local n = v.normalized
Returns a normalized copy of the vector.
Example
local v = Vector2(3, 4)
print(v.length) -- 5
print(v.normalized.x) -- 0.6
Vector3
Construction
local v = Vector3()
local v = Vector3(x, y, z)
Fields
| Name | Type |
|---|---|
| x | number |
| y | number |
| z | number |
Properties
length
local len = v.length
Returns magnitude of the vector.
lengthSquared
local len2 = v.lengthSquared
Returns squared magnitude.
normalized
local n = v.normalized
Returns a normalized copy.
Example
local forward = Vector3(0, 0, 1)
local dir = forward.normalized
Vector4
Construction
local v = Vector4()
local v = Vector4(x, y, z, w)
Fields
| Name | Type |
|---|---|
| x | number |
| y | number |
| z | number |
| w | number |
Notes
Vector4currently exposes only raw component access.- No math properties (length/normalize) are bound yet.
Example
local color = Vector4(1, 0, 0, 1) -- RGBA
print(color.w)