Game Development Community

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? :-)

#1
03/26/2006 (11:23 pm)
You can do this in the collision script-callback by checking the objects and calculating the appropriate response. This shouldn't be a problem as the responses you mention are so simple.

It would be interesting to add the ability to select a response for a single/pair of objects from script though. Noted.

- Melv.
#2
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
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
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.