Video - Trigger Basics

This tutorial demonstrates the use of triggers to switch on and off a light when a given object enters or exits a defined area in space.

Trigger basics.

Script(s) used in this tutorial


The following script is assigned to the item 'Cube'. The OnEnterTrigger callback turns on the light by setting its diffuse intensity to 1.0 while the OnExitTrigger turns it off by setting its diffuse intensity to 0.0.


                          
  1. class myCube
  2. {
  3. my_scene = 0
  4. my_light = 0
  5.  
  6. function OnUpdate(item)
  7. {}
  8.  
  9. function OnSetup(item)
  10. {
  11. my_scene = ItemGetScene(item)
  12. my_light = ItemCastToLight(SceneFindItem(my_scene, "my_light"))
  13. LightSetDiffuseIntensity(my_light, 0.0)
  14. }
  15.  
  16. function OnEnterTrigger(item, trigger)
  17. {
  18. LightSetDiffuseIntensity(my_light, 1.0)
  19. }
  20.  
  21. function OnExitTrigger(item, trigger)
  22. {
  23. LightSetDiffuseIntensity(my_light, 0.0)
  24. }
  25. }

                        

Note: When a light has both of its diffuse and specular intensity set to 0.0 it is not rendered anymore.

However, if the specular intensity is non-zero and the diffuse intensity is set to 0.0 the light specular will still be rendered. To ensure perfect light deactivation one can use the ItemActivate(item, bool) API function.