Creating Pong using Box2D

Jun 22, 2010 at 8:14 AM

So I have been trying to recreate Pong in Box2D to learn how to use the engine and I think its more complicated than i thought. I have the collision down by itself, i have the ball restitution set at 1.0 , my only problem is I have no idea how to have the ball hit the paddle, bounce back at the right angle and have enough speed to reach the other side. I have looked at c++,actionscript but it seems like no one has really fully implemented a pong game.


So far here is what i got


Start off the game

 ballBody.SetLinearVelocity(new Vector2(-50, 100));


it hits the paddle, how do i make the ball pick up speed etc.., thanks



Jul 6, 2010 at 2:10 AM
Edited Jul 6, 2010 at 2:10 AM

What you want is zero friction and 1.0 restitution for all objects.  That will allow the ball to bounce without loosing speed.

To make it gain speed when it hits the paddle you'd want to listen for contacts (set World.ContactListener) and scale the linear velocity on the ball.

You probably also want the paddles to be kinematic bodies so they don't repsond to collisions like a dynamic body would.


Hope that helps.
-Brandon Furtwangler