Use callbacks when the moment of contact matters.
Solid Contacts
For solid contacts, add a method like this to a Behaviour:
use Lenga\Engine\Core\Collision3D;
public function onCollisionEnter(Collision3D $collision): void
{
Debug::info('Touched ' . ($collision->gameObject?->name ?? 'Unknown'));
}
Use Enter when the first moment of contact matters.
Use Stay when the effect should continue while objects remain in contact.
Use Exit when something should happen after the objects separate.
Trigger Volumes
For trigger-style overlaps, enable Is Trigger on the collider and use:
use Lenga\Engine\Core\Collision3D;
public function onTriggerEnter(Collision3D $collision): void
{
Debug::info('Entered trigger: ' . ($collision->gameObject?->name ?? 'Unknown'));
}
Triggers are useful for pickup zones, checkpoints, sensor areas, and invisible volumes.
Contact Data
Collision3D tells you which GameObject and collider touched this Behaviour's GameObject.
Use that data to:
- check tags or layers
- spawn effects at contact points
- play sounds
- apply damage
- activate checkpoints
Where 2D Differs
The 2D callback names include the 2D suffix, such as onCollisionEnter2D(...).