Video Tutorial: How To Use Physical Triggers to Catch Physical Objects
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.
Physical Trigger is a volume that fires callbacks when an object with a physical body and a shape gets inside or outside of it.
The component code displayed in this video is provided below for your convenience:
Trigger.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 Physical : Component
{
vec4 color;
void enter_event_handler(Body body)
{
// Remember the material's color and set it to black
color = body.Object.GetMaterialInherit(0).GetParameterFloat4("albedo_color");
body.Object.GetMaterialInherit(0).SetParameterFloat4("albedo_color", vec4.BLACK);
}
void leave_event_handler(Body body)
{
// Restore the previous material's color
body.Object.GetMaterialInherit(0).SetParameterFloat4("albedo_color", color);
}
PhysicalTrigger physicalTrigger;
void Init()
{
// Cast Node to PhysicalTrigger
physicalTrigger = node as PhysicalTrigger;
if(physicalTrigger){
// Subscribe for Enter and Leave events to perform actions
// when a body enters or leaves the trigger
physicalTrigger.EventEnter.Connect(enter_event_handler);
physicalTrigger.EventLeave.Connect(leave_event_handler);
}
}
void Update()
{
// Render the trigger's volume
Visualizer.RenderNodeBoundSphere(node, vec4.BLUE);
}
}
To enable the visualizer, add the following code in the Init() method in AppWorldLogic.cpp or any suitable component:
Source code (C#)
// Enable Visualizer
Visualizer.Enabled = true;
Last update:
2025-03-04
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)