Game Development Community

Object to object collision

by Tom Feni · in Torque Game Builder · 07/24/2005 (10:36 pm) · 1 replies

Well its me again.. :)

I have decided to try making a pinball game as my first project.. I have the paddles going great and the plunger is in.. but when the plunger drops down and pops back up it sends the ball in a frenzy of bouncing, until the ball gets so fast it goes thru walls with collision..

So what I tried to do is set up a oncollision call so it applied force in one direction.. well it doesnt work apparently as it still does it with the or without it...

so here is the code.. :)

the material for collisions..
datablock fxCollisionMaterialDatablock2D(bouncyMaterial)
{
      friction = 0.1;
      restitution = 1.0;
      relaxation = 0.0;
      density = 0.2;
      forceScale = 2.5;
      damping = 0.0;

};

player code
function setupPlayer()
{
	// Create Player.

   $player = new  fxStaticSprite2D() { scenegraph = t2dSceneGraph; };

   $player.setGroup(2);
   $player.setLayer(0);
   $player.setPosition("105 60");
   $player.setSize( "4.5 4.5" );
   $player.setImageMap( playerImageMap );
   $player.setCollisionPolyCustom( 6, "-0.8 -0.5 0 -1 0.7 -0.5 0.8 -0.3 0.2 0.8 0.8 0.5" );
   $player.setCollisionActive(true, false);
   $player.setCollisionPhysics(true, true);
   $player.setCollisionMasks(0xffffffff, 0xffffffff);
   $player.setMaxAngularVelocity(0);
   $player.setCollisionMaterial(bouncyMaterial);
   $player.setConstantForce("0, 2000", false);
}

function impulseForce()
   {
   $player.setImpulseForce("-500, 500", false);
   }

//Impulse?
   setImpulse( %srcObj );

      if (%srcObj == $player)
         {
         impulseForce();
         }

plunger
function setupPlunger()
{
	// Create Paddles.

   $plunger = new  fxStaticSprite2D() { scenegraph = t2dSceneGraph; };

   $plunger.setGroup(2);
   $plunger.setLayer(2);
   $plunger.setPosition("106 90");
   $plunger.setSize( "10 48" );
   $plunger.setImageMap( plungerImageMap );
   //$plunger.setCollisionPolyCustom( 8, "0.25 -0.6 1 -0.2 1 0.2 0.25 0.5 -0.24 0.5 -1 0.2 -1 -0.2 -0.2 -0.6" );
   $plunger.setCollisionActive(true, true);
   $plunger.setCollisionPhysics(true, true);
   $plunger.setCollisionMasks(0xffffffff, 0xffffffff);
   $plunger.setCollisionMaterial(immovableMaterial);
   
   new ActionMap(plungerMap);
   // Bind keys to actions.
   plungerMap.bindCmd(keyboard, "r", "plungerGo();", "plungerReset();");

   plungerMap.push();
}

function plungerGo()
   {
   // Set the player moving up.
   $plunger.setPositionY(100);

   }

function plungerReset()
   {
   // If we're moving up then nullify any upward movement.
   if ( $plunger.getpositionY() > -100 )
   $plunger.setpositionY( 90 );
   }


so it does work somewhat how I wanted but it is sending the ball wildly out of control in the narrow shoot.. so I may have to just drop the ball out of the top to start and go from there.. unless someone has an idea of where I am goofing up.. :)

thanks for the help if there is any :)

#1
07/25/2005 (4:49 am)
You can try limiting the speed of the ball with
$player.setMaxLinearVelocity( 20 );  // Change the number around until it feels right