Simple pong paddle and ball settings

Topics: Developer Forum
Aug 18, 2007 at 6:23 PM
Edited Aug 18, 2007 at 7:02 PM
Experienced posters,

I am trying to do a simple pong demo with Farseer, but having some issues. I have set up the following bodies with these values.

Paddle;
Mass = 100
RestitutionCoefficient = 0;

Ball;
Mass = 1
RestitutionCoefficient = 1;

But the ball simply travels through the paddle. Not really sure what I am doing incorrectly, or what extra settings/values I need to put in place.

Can someone point me in the right direction?
Aug 18, 2007 at 10:55 PM
The only reasons I can think of why this would happen are:

1. You neglected to add one or both objects to the EntityManager.
2. You put them in like CollisionGroups other than group 0.
3. You, somehow, managed to set CollisionEnabled or CollisionResponseEnabled to false. I don't know why you'd do this, either, but I'm throwing it out there.

But crashlander knows more than I do.
Aug 19, 2007 at 2:58 AM
Edited Aug 19, 2007 at 3:07 AM
Thanks for the reply ccxvi,

I will paste my code thus far.

In the main game Initialize method I have this;
PhysicsSimulator.Gravity = Vector2.Zero;

Ball: (square texture....)
rigidBody = new RectangleRigidBody(Size.X, Size.Y, 1);
rigidBody.RestitutionCoefficient = 1f;
PhysicsSimulator.Add(rigidBody);

Paddle:
rigidBody = new RectangleRigidBody(Size.X, Size.Y, 100);
rigidBody.RestitutionCoefficient = 1f;
PhysicsSimulator.Add(rigidBody);

And in the main game update method I have this simple line:
PhysicsSimulator.Update(gameTime.ElapsedGameTime.Milliseconds * .001f);

I seen the examples that use EntityManager, but from what I understand, its not required and calls other objects methods to the PhysicsSimulator.Add() method. I am not modifying a sample.

And to give you some more background on what I am doing. In my update loop, I query the mouse X, Y and set the paddle's sprite & rigidbody positions. If I move the mouse extreamly slow, the ball does not go through, but if i move the mouse more quickly, then it passes through.
Coordinator
Aug 19, 2007 at 4:41 PM
With a physics engine, you don't normally want to set the body position every game loop yourself. You are probably changing the position of the paddle so fast that it is causing tunneling... This is the same as a fast moving small object hitting second thin object. It's possible for the fast object to move thru the thin object in one time-step. It this happens, Farseer won't even see the collision.

If you need your paddles to mover very quick then I'm not sure Farseer will suit your needs. One possibilty is making the paddle body thicker then the image for it. Farseer would then be able to detect the collision before the ball could go thru it.

-Jeff