Video Tutorial: How To Use World Triggers to Detect Nodes by Their Bounds
Notice
Subtitles are available for each tutorial in English, Russian, and Chinese.
Warning
The tutorial is created with SDK version 2.18. Not applicable for earlier versions.
World Triggers fire callbacks when any nodes (colliders or not) get inside or outside of them. The trigger can detect a node of any type by its bounding box.
The component code displayed in this video is provided below for your convenience:
DeleteObject.cs
using System.Collections;
using System.Collections.Generic;
using Unigine;
[Component(PropertyGuid = "AUTOGENERATED_GUID")] // <-- this line is generated automatically for a new component
public class DeleteObject : Component
{
WorldTrigger worldTrigger;
void enter_event_handler(Node target)
{
// Delete the object on entering the trigger
target.DeleteLater();
}
void Init()
{
// Cast Node to WorldTrigger
worldTrigger = node as WorldTrigger;
if(worldTrigger){
// Subscribe for Enter event to perform actions
// when a node enters the trigger
worldTrigger.EventEnter.Connect(enter_event_handler);
}
}
void Update()
{
// Render node's visualizer
node.RenderVisualizer();
}
}
Mover.cs
using System.Collections;
using System.Collections.Generic;
using Unigine;
[Component(PropertyGuid = "AUTOGENERATED_GUID")] // <-- this line is generated automatically for a new component
public class Mover : Component
{
void Init()
{
// write here code to be called on component initialization
}
void Update()
{
// move the node down
node.Translate(new vec3(0.0f, 0.0f, Game.IFps * -1.0f));
// render the bounding box
Visualizer.RenderBoundBox(node.BoundBox, mat4.IDENTITY, new vec4(1.0f, 0.0f, 0.0f, 1.0f));
}
}
To enable the visualizer, add the following code in the Init() method in AppWorldLogic.cpp or any suitable component:
Source code (C#)
// Enable Visualizer
Unigine.Console.Run("show_visualizer 1");
Last update:
2025-03-04
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)