Game Development Community

How to detect the type of an object

by Michael Hartlef · in Torque Game Builder · 01/24/2008 (6:42 am) · 4 replies

Hi folks,

inside the collision event, I would like to get the type of the destination object. I need this so I can react differently on collisions with TRIGGERS. Any information is welcome.

Michael

#1
01/24/2008 (1:35 pm)
It depends a lot on how you want to set this up. The easiest way AFAIK would be to put the different items in different collision groups and use the getGroup() function on the object you have collided with to get the "type" of the object. For instance, if you have the following collision groups:

1 - Player
2 - Enemies
3 - Tiles
4 - Items
5 - Triggers
6 - Special

Then you can do a case statement within the onCollision() call back to spawn off into the functions you want to handle the different type of collisions.

Does that make sense ?
#2
01/24/2008 (8:43 pm)
Thanks Glenn,

yes it makes sence. But I still hope that there is another way as I wanna but this into a behavior and make it more general.
#3
01/24/2008 (8:52 pm)
There are many ways to do this. What I usually do is use a switch$ command or string comparison test on the object.class...but that only works if you're using different classes for the different object types.
#4
01/25/2008 (12:26 am)
So I can do a string compare to the object class (t2dtrigger) of the triggers. I didn't know that you could do that so easily.
Great, I will try that. Thanks guys for all the suggestions.