Game Development Community

Breakout physics

by Tetraweb · in Torque Game Builder · 01/22/2007 (4:59 pm) · 5 replies

Hi, I'm working on a simple breakout game for a tutorial. I had wanted to have the ball have a RIGID collision response, but have given up and gone to BOUNCE. I wanted the ball to respond to a fast paddle hit versus a slow paddle hit, but can't get around the velocity bleed that eventually slows the ball down to a stop.

I may be missing something; I had the max rotation to zero, and played with different masses of the ball versus the paddle, but all configurations using RIGID resulted in the ball losing velocity over time. What I want obviously is a minimum velocity that it never drops below, but a range that it can accelerate over that.

I am instead fudging it using BOUNCE but checking the velocity of the paddle after a hit, and if it is above a certain speed I am adding a velocity boost to the ball.

Anyone have any insight or a better method?

Greg

#1
01/23/2007 (6:49 am)
You can set the minLinearVelocity to make sure it can't drop below a given speed (this means that the ball at generation will need to have physics disabled) and a maxLinearVelocity for the balls maximum speed.

Normally the min is set to 0, you most likely would just set it to something above.

And if you don't want the ball to become slower, just set its friction to 0, default is > 0, so it will slow down over time.
#2
01/23/2007 (10:50 am)
Thanks for the reply. Yes, I have had the friction set to 0, and still it slows over time. minLinearVelocity had no effect, and in fact my investigating led me to conclude that what you are setting with that variable is the velocity which should be 'considered' 0 in effect by the physics system. My understanding is that it exists to prevent unstable, continuing movement by items that should be considered 'at rest.'

I don't understand your statement that the ball at generation would need to have physics disabled if you are setting the minlinvel. Why would that be?

Greg
#3
01/26/2007 (5:04 am)
After more testing, I must conclude that I have to use bounce mode for the ball. You can see in the function below some of the factors I was changing, but all my testing with RIGID mode resulted in the ball losing velocity over time as it collided with various things. I was right about minlinearvelocity; setting it to 40 for example resulted in the ball being placed atRest if its velocity dropped below that.

function ballClass::onLevelLoaded(%this, %scenegraph) 
{ 
	$theball = %this;
	$theball.setMass(3.5);
	//$theball.setMinLinearVelocity(40); sets the velocity below which it should be considered at rest
	$theball.setMaxAngularVelocity(4);
	$theball.setMaxLinearVelocity(80);
	$theball.setRestitution(1.0);
	$theball.setFriction(0);
	$theball.setCollisionPhysics(1,1); //send , recieve
	$theball.setCollisionResponse(BOUNCE);
}

If anyone has any input I would love to hear it. Thanks.

Greg
#4
01/27/2007 (8:39 am)
You use the collision callback and re-apply your velocity when your object collides with anything if it is below your minimum speed

function ballclass::onCollision(%this)
{

   %angle = getword(%this.getlinearVelocitypolar(),0);
   %speed = getword(%this.getlinearVelocitypolar(),1);
   
     
   if (%speed < 40)
      %this.setlinearvelocitypolar(%angle, 40);

}

//Remember to enable the collision callback on your object
$theball.setCollisionCallback(1);
#5
02/02/2007 (3:53 am)
That works well. Excellent suggestion, why didn't I think of that. Thank you, Guy.

Greg