Game Development Community

Trigger objects

by Mike Lilligreen · in Torque 2D Professional · 05/25/2013 (2:54 am) · 2 replies

Looking through the trigger code, it is basically just a SceneObject with 3 extra callbacks added for when another object enters/stays/leaves.

Just out of curiosity, are there practical reasons for this to be a separate class (besides the fact that the name clearly lets you know what it is) instead of rolling those callbacks into SceneObjects? Then other objects like Sprites can directly be triggers without having to create 2 objects in a scene to get the same functionality.

Edit: perhaps better phrased, would there be interest in merging the trigger functionality into SceneObject or should they be kept separate?

#1
05/25/2013 (7:24 pm)
That object could go away - use a SceneObject and put a collision shape on it set as a sensor. I'm pretty sure Box2D has a way of telling you when a collision starts and when it ends, and I could swear that Melv put in a ticking callback as long as something is inside the sensor too - so it should do everything that a trigger does.
#2
06/03/2013 (1:27 am)
Just looked at the trigger class and it's indeed pretty badly designed and mostly useless now. But it could be a good idea to add a way to register trigger callback object to a scene object which in turn assign it to one of its collision shapes and thus not have to deal with box2d (ie any reference to it should really be abstracted away from any external calls) the callback object could then call a function pointer on the desired sim object signalling the event.

It is definitively working as it is now, could be a bit more friendly when it comes to sensor, but work.