Collision response KILL
by Bojan Vukojevic · in Torque Game Builder · 03/14/2011 (2:21 pm) · 19 replies
Hello,
I created 2 exactly the same objects and turned send and receive collision on them. Collision response is KILL and when they collide both of them are deleted as it was intended. The thing is i would love just to add maybe an explosion or something similar when that happens. I can do it on onCollision event but i would like to skip unnecessary code when i almost have what i need. Is it possible to capture onKILL or onDeleteObject? I looked around and couldn't find anything similar to that. Only thing that could help me is collision response CUSTOM, but i do not have the source and not sure if it is possible in script. Any ideas?
I created 2 exactly the same objects and turned send and receive collision on them. Collision response is KILL and when they collide both of them are deleted as it was intended. The thing is i would love just to add maybe an explosion or something similar when that happens. I can do it on onCollision event but i would like to skip unnecessary code when i almost have what i need. Is it possible to capture onKILL or onDeleteObject? I looked around and couldn't find anything similar to that. Only thing that could help me is collision response CUSTOM, but i do not have the source and not sure if it is possible in script. Any ideas?
#2
03/28/2011 (4:06 am)
Thanks for the reply Lonnie. I am using the onCollision now. The thing is with onCollision you catch every collision with every object. For example, if you have a trigger mounted on that object the 2 will collide all the time and onCollision function will be called who knows how many times per sec. I was just hoping that i can just catch the kill "event" and maybe save some performance, because i may end up with quite a few objects at the end. I had some problems with performance earlier and now i try to minimize as much as i can.
#3
03/28/2011 (4:54 am)
Use the supplied parameters to filter out things. %srcObject could also be named %this. %dstObject is the object being collided with. Using a custom response you can skip processing for some objects, and start fancier animations and sounds for special cases.
#4
03/28/2011 (5:00 am)
The problem with CUSTOM is that you can only use it if you have a source code if i understood it right, and i do not have the code. Question is can you use CUSTOM just with script?
#5
03/28/2011 (6:12 am)
One more thing just to explain it a little beter: when i say CUSTOM i mean colliosionResponse not custom if/switch logics in onCollision funciton. According to TDN you can set few responses (rigid, kill etc etc) and one of them is CUSTOM.
#6
03/30/2011 (12:42 pm)
Filtering out objects to collide with is where things like setCollisionGroups, setCollisionMasks, and setCollisionLayers come in handy. With these you can limit what an object will collide with based on either it's Group number, the Layer it is on, or based on a Mask (list of objects).
#7
03/30/2011 (12:47 pm)
I could be completely off base here but don't sprites have an onAdd and onRemove callback function? Couldn't you use that?
#8
Atm i'm using onCollision but if i get into performance problems i think i will use masks and layers.
Thanks for the help guys :)
03/30/2011 (1:17 pm)
Actually masks and layers could help in my case, i completely forgot about that. And tbh i couldn't see what are you pointing at Chris, but after a min of thinking onRemove could actually be what i am looking for. Unfortunately i looked on tdn briefly and in http://tdn.garagegames.com/wiki/TGB/Reference:_t2dSceneObject_Callbacks i can only see onAdd no on remove. Atm i'm using onCollision but if i get into performance problems i think i will use masks and layers.
Thanks for the help guys :)
#9
I was under the impression that an onRemove was called as well, just before the object was deleted. If one is called then that is exactly what you are looking for.
03/30/2011 (1:19 pm)
When an object is added to a scene an onAdd callback is called on the object. I was under the impression that an onRemove was called as well, just before the object was deleted. If one is called then that is exactly what you are looking for.
#10
I'm pretty sure it does call onRemove. Try this:
03/30/2011 (1:22 pm)
void TickableScriptObject::onRemove()
{
// Call onRemove in script!
Con::executef(this, 2, "onRemove", Con::getIntArg(getId()));
Parent::onRemove();
}I'm pretty sure it does call onRemove. Try this:
new t2dStaticSprite() {class="myObject";... etc.};
function myObject::onRemove(%this)
{
echo("IT WORKED");
}
#11
03/30/2011 (1:25 pm)
Heh i just tried onRemove and it works :) Of to do some changes...
#12
03/30/2011 (1:26 pm)
boo yah!
#13
03/30/2011 (1:30 pm)
i owe you a beer :)
#14
03/30/2011 (4:28 pm)
and one day we will meet and you will owe me said beer.... You don't happen to be from Canada, do you? :D
#15
03/31/2011 (12:58 am)
well i'm not that far. i just need to cross half of Europe and the Atlantic but is relatively near if you consider that beer is involved :)
#16
If you like anything stronger, or with a fuller flavor than a Lager bring your own Beer! ;)
03/31/2011 (3:03 am)
Pssst...BojanIf you like anything stronger, or with a fuller flavor than a Lager bring your own Beer! ;)
#17
03/31/2011 (5:41 am)
Why you gotta hate? Besides, us Canadians have a wide range of imported beverages from European countries.
#18
04/01/2011 (3:22 pm)
Just messin' with ya Chris. Hence the wink ;)
#19
04/01/2011 (3:23 pm)
I know :)
Torque 3D Owner Lonnie Shaw
function myClass::onCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points)
{
Your_Partical_Effect_Code_Here
}