Collision Detection
by Rob Evans · in Torque X 2D · 05/15/2007 (5:39 am) · 6 replies
I've implimented the supplied OnCollision delegate stuff in the documentation and that works fine for my game logic like destroying a player and creating an explosion etc but is there a way to have a function called when a collision occurs so that I can determine in that function what action is taken like bounce, clamp, kill etc?
Basically, if there's a collision, I want my function to be called with the two objects that collided as parameters, then I want to pass back or control what happens when those two objects collide without using any preset info in the XML files or in any setup code.
Basically, if there's a collision, I want my function to be called with the two objects that collided as parameters, then I want to pass back or control what happens when those two objects collide without using any preset info in the XML files or in any setup code.
#2
Yeah, I'm already doing that... but it still doesn't help me define what actually happens with the ResolveCollision. I want to be able to change the ResolveCollision based upon what objects have collided. I can already call any function I like using arguments in my switch statement. Can I call a function to apply bounce to the objects that collide even though they originally had KillCollision set for their ResolveCollision ?
05/16/2007 (7:00 am)
Hi ya,Yeah, I'm already doing that... but it still doesn't help me define what actually happens with the ResolveCollision. I want to be able to change the ResolveCollision based upon what objects have collided. I can already call any function I like using arguments in my switch statement. Can I call a function to apply bounce to the objects that collide even though they originally had KillCollision set for their ResolveCollision ?
#3
Example:
if (theirObject.ObjectType & TorqueObjectDatabase.Instance.GetObjectType("Enemy"))
{
resolve = T2DPhysicsComponent.RigidCollision; // or bounce etc.
}
05/16/2007 (8:03 am)
I've been doing this by setting the resolve T2DResolveCollisionDelegate in OnCollision.Example:
if (theirObject.ObjectType & TorqueObjectDatabase.Instance.GetObjectType("Enemy"))
{
resolve = T2DPhysicsComponent.RigidCollision; // or bounce etc.
}
#4
05/16/2007 (8:10 am)
Hmm.. I thought I'd given that approach a try and it said the property was read-only, however I was very tired at the time so I'll give it another go!
#5
05/16/2007 (8:22 am)
Awesome... it worked... I'm not sure how I screwed this up last time I tried it! Thanks for your help Alex!
#6
05/24/2007 (9:05 am)
Just to poke an official nose in here: that's the correct way to do it. The resolve is passed in specifically for that purpose. :)
Torque 3D Owner Harrison Brock