Game Development Community

Collision with one object killed and other bounced

by Steven Hine · in Torque Game Builder · 05/29/2006 (10:09 am) · 2 replies

I'm trying to make one object bounce of another, but have one object killed on contact. Like in a breakout style game. Anyone have an idea how I can do this?

#1
05/31/2006 (1:48 pm)
The following code assumes that you have an object with the class of "Ball" colliding with an object with the class of "Block"

function Block::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts )
{
   if(%dstObj.class $= "Ball")
   {
         // If a ball hit us, or we hit a ball... (we are dead)
         // Then delay destroy ourselves so the ball bounces!
         %srcObj.schedule(20, "destroyBlock");
   }                   
}

function Block::destroyBlock(%this)
{
   %this.safeDelete();
}

Also, you will have to change your collision response for your ball. To do this, go into the edit tab of your ball object and find the collision rollout. Inside the collision rollout, change your response mode to "BOUNCE". Hope this helps out!
#2
05/31/2006 (7:40 pm)
Thanks! I just learned a lot about the way the callback works.