Bouncing balls (nudge nudge)

Topics: User Forum
Oct 7, 2009 at 1:17 PM


First of all... I'm VERY new to the Farseer Physics Engine so please bear with me.

As I said I'm only just getting started with Farseer and I'm trying to get two balls to bounce around the screen.
I want them to travel at the same speed all the time. And I only want to change their direction when they hit something.

How can I achieve this?

Oct 7, 2009 at 11:01 PM

For starters, you could try adjusting the Physics Properties (that manual is a good place to start learning about Farseer). More specifically, you'll want to set:

 LinearDragCoefficient = 0;

 RestitutionCoefficient = 1;

 FrictionCoefficient = 0;

You'll also want to set gravity (a force applied to all movable objects every frame) to equal Vector2.Zero. Try that out and come back if you have more questions.

Oct 9, 2009 at 7:42 AM

Thanks! That helped alot. I did read the manual and had allready set RestitutionCoefficient = 1 and I also created my physics simulator without gravity.

The only thing left (I guess) is to stop items from applying forces to each other on collision. The problem I'm having now is that when the balls collide with my borders they slow down dramatically. And when they collide with each other the sometimes speed up, sometimes slow down. I know that this is perfectly normal and intended. But is there a way to override this behavior, to keep the balls moving at the same speed all the time?


Oct 9, 2009 at 12:25 PM

The reason that happens is because of approximated circles instead of real circles. You are essentially using a n-gon instead of a circle and that can cause some weird behavior. One thing is to make the collision between walls and circle consistent. You can do that by disabling rotation on the circles.

However, when the circles hit each other, they will still slow-down or speed up. One thing you could do is to calculate the difference in force (between intended and real force) and then apply the force needed accordingly. Like a force-buffer if you will.