Lua Trigger
From BeamNG
Language: | [[::Lua Trigger|English]] |
---|
BeamNG Lua Trigger can be used to execute custom lua code when entering or exiting them.
Lua trigger in the editor
Enter the level editor (by pressing F11) and navigate to the SceneTree (at the top right corner of the window). Go to the Level tab and open up the BeamNG folder. By double-clicking on the BeamNG Lua Trigger entry you can create a new trigger in your scene.
Property | Type | Description |
---|---|---|
name | string | The name of the trigger. Simple as that! |
id | number | Can be used to add conditions to code to do soemthing with this particular trigger |
position | Float3F | The position of the trigger |
rotation | Float4F | The rotation of the trigger |
scale | Float3F | The scale of the trigger |
TriggerType | Box or Sphere | Defines the shape of the trigger |
luaFunction | string | This code snippet will be called once the vehicle enters/exits the trigger |
ticking | bool | If this property is enabled, the added luaFunction will be called every certain amount of time |
tickPeriod | number | Is the time (in ms) that elapses until the luaFunction gets called again |
There are actually some more properties but these are the most important ones.
Lua code example
local function myGravityTrigger (data) if data.event == "enter" then environment.setGravity(0) else environment.setGravity(-9.81) end end return myGravityTrigger
If you add this code snippet to your lua trigger, the gravity will change to 0 when entering the trigger and will be set back to the default of -9.81 once you exit it again.
Just changing the gravity might be a bit boring over time. So take a look at the lua reference page to see which other opportunities you have.