Different collision response per pairing of colliding objects
by Jason Cahill · in Torque Game Builder · 03/26/2006 (10:11 pm) · 5 replies
OK, here's the scenario I'm trying to accomplish:
I have:
A) Allied tank
B) Enemy tank
C) Allied tank shell
D) Enemy tank shell
E) Obstacles
I want to define differing collision responses based on the 2D matrix of [A B C D E] x [A B C D E].
For example:
A collides with:
A = Bounce both src and target
B = Bounce both src and target
C = Kill target (C) (friendly fire doesn't hurt allied tanks)
D = Kill src (A) & target (D)
E = src (A) clamps, target (E) is immovable
Here's what I think I want:
in my onCollision callback, I want to be able to define the src and target response to this collision. Then, I can just have everything collide with everything else and in the onCollision callback, I can figure out based on the groups of the source and target what should happen. I assume this isn't possible today?
I can't find anyway to say: "A & E just collided, so make A clamp to E and leave E alone."
Any ideas? :-)
I have:
A) Allied tank
B) Enemy tank
C) Allied tank shell
D) Enemy tank shell
E) Obstacles
I want to define differing collision responses based on the 2D matrix of [A B C D E] x [A B C D E].
For example:
A collides with:
A = Bounce both src and target
B = Bounce both src and target
C = Kill target (C) (friendly fire doesn't hurt allied tanks)
D = Kill src (A) & target (D)
E = src (A) clamps, target (E) is immovable
Here's what I think I want:
in my onCollision callback, I want to be able to define the src and target response to this collision. Then, I can just have everything collide with everything else and in the onCollision callback, I can figure out based on the groups of the source and target what should happen. I assume this isn't possible today?
I can't find anyway to say: "A & E just collided, so make A clamp to E and leave E alone."
Any ideas? :-)
About the author
#2
Thanks for the quick response. I agree that "kill" and "bounce" are easy, but "clamp" and "sticky" are not as easy to compute... it requires that you know the shape of the collision poly in order to track along it, right? Maybe I'm just being dumb.
It seems like what we need here is a pair of "out" params in the callback where you can set what the response for the source and target objects are. Actually, maybe it's just the return value of the function? You could return "kill kill" or "kill none" or "bounce none", etc one for source and one for target.
03/26/2006 (11:38 pm)
Hi Melv,Thanks for the quick response. I agree that "kill" and "bounce" are easy, but "clamp" and "sticky" are not as easy to compute... it requires that you know the shape of the collision poly in order to track along it, right? Maybe I'm just being dumb.
It seems like what we need here is a pair of "out" params in the callback where you can set what the response for the source and target objects are. Actually, maybe it's just the return value of the function? You could return "kill kill" or "kill none" or "bounce none", etc one for source and one for target.
#3
The "onCollision" callback returns the point(s) of contact as well as the collision normal. Using these, you can easily do a "sticky" (stop) response by moving to the contact point and setting the object to rest. For "clamp", you can move to the contact point and calculate the resultant vector using the algorithm in "t2dPhysics::resolveClampCollision". You'd also need the contact-point for "bounce".
The idea of returning values that TGB can then action occurred to me quite a while ago but there were a few reasons why it's not a good idea. A nicer way and something that's not restricted to the "onCollision()" is to expose the stock responses to the scripts.
Hope this helps,
- Melv.
03/27/2006 (1:57 am)
Jason,The "onCollision" callback returns the point(s) of contact as well as the collision normal. Using these, you can easily do a "sticky" (stop) response by moving to the contact point and setting the object to rest. For "clamp", you can move to the contact point and calculate the resultant vector using the algorithm in "t2dPhysics::resolveClampCollision". You'd also need the contact-point for "bounce".
The idea of returning values that TGB can then action occurred to me quite a while ago but there were a few reasons why it's not a good idea. A nicer way and something that's not restricted to the "onCollision()" is to expose the stock responses to the scripts.
Hope this helps,
- Melv.
#4
03/27/2006 (7:50 am)
Yeah, this is perfect for now--I understand the workaround. As you suggest, I'd love to see this extended longer term from script as just collision responses. Thanks for the help!
#5
- Melv.
03/27/2006 (11:40 am)
Anytime Jason. It's a very good idea to get some access to stock responses and I'll do my best to find the time to get it done!- Melv.
Associate Melv May
It would be interesting to add the ability to select a response for a single/pair of objects from script though. Noted.
- Melv.