Game Development Community

Physics demo tutorial doesn't work with Beta1?

by John Klimek · in Torque Game Builder · 02/09/2006 (8:39 am) · 2 replies

I'm trying to following the physics demo tutorial but the balls (well, blocks) don't bounce around like they are supposed to. First off, they go waay too fast from the center to the walls so I lowered the ImpulseForcePolar speed from 700 to 50 and that helped, however when the block hits a wall it simply stops OR slides along the wall until it reaches a corner. It doesn't bounce off the wall or anything like that.

Here is the code taken straight from the tutorial:

function pongBounce()
{
   // Setup some immovable walls and allow them to receive collisions only...

   // Left.
   %sprite = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
   %sprite.setPosition( "-40 0" );
   %sprite.setSize( "2 75" );
   %sprite.setImageMap( tileMapImageMap );
   %sprite.setCollisionActive( false, true );
   %sprite.setImmovable();
   // Right.
   %sprite = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
   %sprite.setPosition( "40 0" );
   %sprite.setSize( "2 75" );
   %sprite.setImageMap( tileMapImageMap );
   %sprite.setCollisionActive( false, true );
   %sprite.setImmovable();
   // Top.
   %sprite = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
   %sprite.setPosition( "0 -33" );
   %sprite.setSize( "80 2" );
   %sprite.setImageMap( tileMapImageMap );
   %sprite.setCollisionActive( false, true );
   %sprite.setImmovable();
   // Bottom.
   %sprite = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
   %sprite.setPosition( "0 33" );
   %sprite.setSize( "80 2" );
   %sprite.setImageMap( tileMapImageMap );
   %sprite.setCollisionActive( false, true );
   %sprite.setImmovable();

   // Bouncy Material.
   datablock fxCollisionMaterialDatablock2D(bouncyMaterial)
   {
      friction = 0;
      restitution = 1.0;
      relaxation = 0.5;
      density = 0.01;
      forceScale = 1;
      damping = 0;
   };

   $blocks::amount = 0;
}

function createBlock()
{

   $blocks::names[$blocks::amount] = "block" @ $blocks::amount;
   // Create Bouncy Ball.
   %ball = new fxStaticSprite2D($blocks::names[$blocks::amount]) { scenegraph = t2dSceneGraph; };
   %ball.setSize( 4 );
   %ball.setImageMap( tileMapImageMap );
   %ball.setCollisionActive( true, true );
   %ball.setCollisionPhysics( true, true );
   //%ball.setLayer( 0 );
   //%ball.setGroup( 0 );
   %ball.setCollisionMasks( BIT(0), BIT(0) );
   %ball.setCollisionMaterial( bouncyMaterial );
   %ball.setMaxAngularVelocity( 0 );

   // Give it a random direction.
   %ball.setImpulseForcePolar( getRandom()*360, 700 );

   $blocks::amount++;
}

#1
02/09/2006 (12:19 pm)
Did you try grabbing the version off of TDN ? :) It's been edited and updated there a couple times (thanks to Spider as well).
#2
02/09/2006 (3:33 pm)
Hmmm, I can't seem to find it on the TDN...

Can you give me a link or tell me where it's at?