Game Development Community

Alpha 2 Ricochet Problem

by Scott Lahteine · in Torque Game Builder · 01/24/2006 (1:09 am) · 5 replies

My game has a series of balls that are supposed to bounce against each other. But in Alpha 2 they don't work correctly. Those that are already moving will bounce off the others, but the ones they hit don't move at all. I've tried several different collision materials with no effect.

Is this a known issue with Alpha2, that physics are broken? I'm using the Mac OS X build.

Here's the code I'm initializing the balls with, if it helps...
datablock t2dCollisionMaterialDatablock(heavierMaterial)
{
  immovable = 0;
  friction = 0.0;
  restitution = 1.0;
  density = 0.000001;
  forceScale = 1.0;
  damping = 0.0;
};

function CreateBalls(%count)
{
  for (%a=0; %a<%count; %a++)
  {
    %ball = new t2dStaticSprite()
    {
      scenegraph = myGameScene;
      isProjectile = true;
      strikeSound = $sndBall;
    };

    %ball.setImageMap( imageBall );
    %ball.setSize( 32 );

    %ball.setMaxAngularVelocity( 360*4 );
    %ball.setWorldLimit( BOUNCE, "-512 -384 512 384" );
    %ball.setPosition(((getRandom() * 800) - 400) SPC ((getRandom() * 600) - 300));

    %ball.setGroup( $ballGroup );
    %ball.setLayer( $ballLayer );
    %ball.setCollisionActive( true, true );
    %ball.setCollisionPhysics( true, true );
    %ball.setCollisionMasks( BIT($paddleGroup)|BIT($bumperGroup)|BIT($ballGroup),
                             BIT($paddleLayer)|BIT($bumperLayer)|BIT($ballLayer) );
    %ball.setCollisionCallback( true );
    %ball.setCollisionMaterial( heavierMaterial );
    %ball.setCollisionDetection( CIRCLE );
    %ball.setCollisionCircleSuperscribed( false );
  }
}

I can't find any flaws in my code. Why would these objects be unresponsive?

#1
01/24/2006 (6:47 am)
%ball.setCollisionResponse(BOUNCE);

I think i read somewhere that the default for that was changed, but that might have just been for alpha3, and you're using alpha2 :S
#2
01/24/2006 (1:05 pm)
Yeah, I tried that. No dice. The objects that get hit still don't move regardless of whether the setting is BOUNCE or CLAMP (the default). They just sit there. Any other ideas?
#3
01/24/2006 (1:28 pm)
I was having a similar issue, but I changed the setCollisionResponse to RIGID, and then my objects would get impulse from things that hit them. Just testing it now, it seems as though the BOUNCE setting will not send an impulse to the thing that it hits, if it's stationary.

This kind of makes sense, but I'm just guessing. I believe that BOUNCE just alters the orientation of the vector of an already moving object, it doesn't do any acceleration or damping or friction, or anything like that.

Try setting it to RIGID, and see if that works.

EDIT
This also makes sense, because I believe that RIGID used to be the default collision response. Not sure though.
#4
01/24/2006 (5:03 pm)
Aha! Thanks Phil. Setting the collision response to RIGID made everything work. After making the change I'm back in business.

One thing I noticed, which is kind of amusing but definitely an Alpha 2 bug, is that I can cause objects to go so fast that they jump over their WorldLimits boundaries, and disappear into the void beyond. Maybe they're getting destroyed, but I haven't checked. I hope this issue is fixed in Alpha 3, because I want these projectiles to go at very high speeds.
#5
01/24/2006 (7:54 pm)
Glad you got it working!