TSStatic and Vehicle Collision
by Matthias Schoeldgen · in Torque 3D Beginner · 01/25/2013 (7:36 am) · 3 replies
I'm sorry to be a pest again on the collision stuff, but for the sake of it i haven't found a solution for my problem yet. I have successfully implemented collision damage for our vehicles, working for vehicle-vehicle, vehicle-player and vehicle-staticshape collisions, mostly thanks to Henry Todd's code. But i can't make it work for collisions between vehicles and TSStatics. Yes, i know that using staticshapes would work around that but i can't do that for e.g. forests. Of course i don't want to damage the tree, but only the vehicle.
It seems as if the onCollision callback is only fired for the target of the collision and not the initiator. So what you guys do to damage a car if it runs into a tree? I'm not afraid of source code changes but haven't yet been able to find the spot for implementing a callback for the initiator of the collision. After spending a few hours searching the site i still couldn't find a useful hint. Please be so kind as to point me in the right direction.
It seems as if the onCollision callback is only fired for the target of the collision and not the initiator. So what you guys do to damage a car if it runs into a tree? I'm not afraid of source code changes but haven't yet been able to find the spot for implementing a callback for the initiator of the collision. After spending a few hours searching the site i still couldn't find a useful hint. Please be so kind as to point me in the right direction.
About the author
Coder, Modeller and Texturer for the eXperience World War 2 (XWW2) Modification for BF2 and BF1942. Playing Bass Guitar and doing electronics in real life.
#2
Once i ram staticshapes and other 'real' objects i get the callback as expected. (ok, it doesn't work for Michael Halls 'Bouncing, yet destroyable Boulder' 100% correctly but theres a callback allright.) And running bots over even gives that 'Sam & Max in a DeSoto' feeling :-)
Oh, one more thing, if i convert each and every tree in our game to a staticshape could i build a forest with them? Anyone tried that yet? And would i have swaying branches and leaves? Wouldn't want to sacrifice that, its such a nice thing to have.
01/25/2013 (10:45 pm)
Thanks for your reply. I have test messages in the callback but unfortunately it will never be called, regardless of the speed with which i try to chop that tree, hehehe. Thats why i believe that only the target of the collision fires 'onCollision' and not the initiator. Once i ram staticshapes and other 'real' objects i get the callback as expected. (ok, it doesn't work for Michael Halls 'Bouncing, yet destroyable Boulder' 100% correctly but theres a callback allright.) And running bots over even gives that 'Sam & Max in a DeSoto' feeling :-)
Quote:Yeps, i think it will be the only option. If it only delivers the objects ID in a callback i'd be happy to implement the rest by script. It stops the car, so the collision must be handled somewhere, probably in the basic collision. 'T3D/Shapecollision.cpp' looks harmless enough to implement some test messages and thats where i probably should start.
One of these days I might start checking the source before trying to answer these.
Oh, one more thing, if i convert each and every tree in our game to a staticshape could i build a forest with them? Anyone tried that yet? And would i have swaying branches and leaves? Wouldn't want to sacrifice that, its such a nice thing to have.
#3
01/27/2013 (6:03 am)
I found the rather simple answer. The trick is to use the 'onCollision' callback for object-object collisions and the 'onImpact' callback (which i found after studying the source) for the other collisions. This callback delivers the same values as the 'onCollision' does and allows for the needed damage calculations. The ID of the target will be 0 in case of colliding with a TSStatic.
Torque Owner Richard Ranft
Roostertail Games
One of these days I might start checking the source before trying to answer these....