Collision enter - exit event?


Is there any way to trigger a collision enter and exit callback? I want to trigger a sound when a user overlaps a gameobject. But I only want the sound to trigger when the user first overlaps the gameobject. As it stands now the sound is being triggered multiple times because the overlap method is being called for as long as the user is overlapping the gameobject (if that makes sense!).


Maybe you want to set a flag of some sort inside the collision callback and reset it at the end of the scene’s update method or as soon as the sounds ends.



I was trying to do the same but instead of adding a dynamic Body to the zone, I was adding a StaticBody. My code wasn’t working and after hours of searching i found that the StaticBodies don’t have an update() method that reset the touching and wasTouching flags. So once an overlap was triggered, the touching and wasTouching objects will keep the left/right/up/down flags set to true, even when the StaticBody is not colliding/overlapping anymore.

Is this the intended behaviour or is this a bug? :thinking:


It is intended that static bodies never update. Maybe the docs should say “Never use these properties”. I think they’re kept for compatibility with the dynamic bodies.