Game Bindings - BenBerke/Tilky-Engine GitHub Wiki

Game Bindings

The Game table exposes high-level engine and editor functionality to Lua scripts.


Functions

LoadLevel

Game.LoadLevel(levelName)

Loads a level/scene by name.

Parameters

Name Type Description
levelName string Name of the level to load

Returns

nil

Example

Game.LoadLevel("TestMap")

Raycast

Game.Raycast(position, direction, length, ignoredID, requireCollider)

Casts a ray through the current level and returns information about the first object it hits.

If the ray does not hit anything, the function returns nil.

Parameters

Name Type Description
position Vector3 Starting position of the ray
direction Vector3 Direction in which the ray travels
length number Maximum distance the ray can travel
ignoredID number Entity ID that the ray should ignore
requireCollider boolean Whether an entity must have a collider to be detected

Returns

table | nil

The returned table contains the following properties:

Property Type Description
type string Name of the hit type
typeID number Numeric identifier of the hit type
position Vector3 World position where the ray hit
distance number Distance from the ray origin to the hit
entityID number ID of the hit entity, or an invalid entity ID
wallID number ID of the hit wall, or an invalid ID
sectorID number ID of the hit sector, or an invalid ID
entity Entity or nil The hit entity
wall Wall or nil The hit wall
sector Sector or nil The hit sector

Example

local origin = Owner.transform.position
local direction = Vector3(0, 0, 1)

local hit = Game.Raycast(
    origin,
    direction,
    100.0,
    Owner.id,
    true
)

if hit == nil then
    Debug.Print("The ray did not hit anything")
    return
end

Debug.Print("Hit type:", hit.type)
Debug.Print("Hit distance:", hit.distance)
Debug.Print("Hit position:", hit.position)

if hit.entity ~= nil then
    Debug.Print("Hit entity:", hit.entityID)
end

if hit.wall ~= nil then
    Debug.Print("Hit wall:", hit.wallID)
end

if hit.sector ~= nil then
    Debug.Print("Hit sector:", hit.sectorID)
end

Notes

  • LoadLevel immediately triggers a level change through the editor or runtime system.
  • Unsaved runtime state may be lost when changing levels.
  • Raycast returns nil when nothing is hit.
  • Only the relevant entity, wall, or sector property is populated for a hit. The other object properties are nil.