This project has moved. For the latest updates, please go here.

Rolling Ball

Aug 28, 2009 at 2:08 PM

Hi all,

I'm still tweaking around my character physics model and I'm hitting a strange difficulty. I'm using the typical box with circle method, but something that's bothering me is that when the ball rolls over a flat surface it slightly bounces up and down along the way. This happens every few frames.

The visual effect is so slight that I could live with it, but the thing is that this bounce implies that the ball ceases to be in contact with the ground every couple of frames, and this is messing up my logic.

From what I've seen of Farseer, I understand that sphere collision detection is not perfect (i.e. mathematically computed), but is instead based on a polygon-approximation. This could well mean that this bouncing effect is expected rather than an odd issue. Is this the case? Is there any way in which rolling balls can be made to traverse smoothly across a flat surface without losing contact with it at any moment? I've already fiddled with the 'numberOfEdges' parameter, but no matter how I increase it the effect is never completely fixed. In fact, for large numbers it actually worsens the effect (as expected).

Best regards,


Aug 28, 2009 at 2:42 PM

What I do is to check if the geometry (the circle in this case) hasn't collide in the last 20 or 30 ticks, then I consider that it isn't colliding with the ground.

Aug 28, 2009 at 8:11 PM

Yes, that is the case. It bounces because of the approximation of the circle. You can do as pnikosis said or create a sensor geometry that is slightly bigger than the circle geometry. The engine works with iterative algorithms, so the result of each timestep might not be 100% correct. You can even get a non-contact situation (rare) from a resting square on another square because of small errors (expected errors) in the calculations.

Aug 28, 2009 at 11:07 PM

Thanks for both suggestions.

I had already tried the skipping ticks method, but for my animation system to remain responsive I couldn't afford to give it more than 2/3 ticks tolerance, and with such slight margins things could still go bad on rare occasions.

In my case I went for a regular geometry with no collision response slightly below the circle. This is because sensor geometries can't collide with static bodies (i.e. the floor), as mentioned in a recent post about jumping. However, this method works great :-)

In fact, given this method I don't understand the practical difference between a sensor geometry and a regular geometry with no collision response. They can be used for pretty much the same purposes, but the geometry with no collision response currently has the following advantages:

- detects static geometries

- doesn't require an extra body (i.e. you can just attach it to your regular moving body)

Thanks for the help,


Aug 29, 2009 at 1:04 AM

Yeah, I keep forgetting that. :)

A sensor is meant to be stationary and not detect other static geometries. You did the right thing and disabled collision response and attached it to the same body. (geometries attached to the same body does not collide)