This project has moved and is read-only. For the latest updates, please go here.

Adjacent static bodies cause hiccups

Topics: Developer Forum, User Forum
Feb 18, 2009 at 12:58 AM
First off, great engine!

I have a square body/geometry sliding along a flat static surface - a square box sliding on ice. When the surface is one long, continuous geometry, the physics are perfect. However, if the surface is instead many smaller, adjacent, separate geometries, the box will "hiccup" sometimes, and rotate into the air or jitter a little bit. I think the problem happens because there are two contact points at the same place, so the box body might hit the upper left contact point of the oncoming surface geometry, and read that as a collision that would cause the box to jump a little bit.

Using one long geometry would be fine, except I want to simulate the box sliding down long stairs, and I want to add and remove bodies and geometries  dynamically as the box moves through the simulation. Essentially, I'm stuck with having to place surface geometries next to each other. Is there an easy workaround for this problem?

I tried twiddling with restitution coefficients, allowed penetration, friction coefficients and types, etc., but it never seemed to erase the problem (although the minimum friction type seemed to ease it somewhat.)

I suppose I could try removing one of the overlapping contact points on the surface geometries. Is there an easy way to do this, even after using a geomFactory to make all the geometries? Or is there an easy way that overlapping contact points could be reduced to considering one point only?

Once again, great engine. Once I solve this bug, I'll share the code so everyone can try it!
Thanks in advance for any input.
Feb 18, 2009 at 11:13 AM
Have you tried overlapping the geometries a little?
You can also reduce the number of contacts detected and resolved by the engine. (MaxContactsToResolve and MaxContactsToDetect in the PhysicsSimulator class)

Oh, and you always have the possibility of removing/ignoring the doublecontacts by removing/ignoring contacts that have the same position.
Feb 18, 2009 at 5:47 PM
Thanks for the quick reply!

Overlapping geometries does not fix the problem, and fiddling with max contacts to detect and resolve didn't seem to work.

The possibility of removing/ignoring contacts that have the same point seems like it's the best way to go, for sure. I don't want to remove the same contact point each time, though. I believe the problem is caused when the box hits the upper-left contact of the oncoming geometry, but the box may be moving left or right, so I can't rely on ignoring the same contact in each geometry.

Anyway, how would I go about removing/ignoring contact points? would I just cycle through the contact list in the simulator object and evaluate which contacts have the same position?

Are the contact points stored in a left-to-right fashion? It would be really exciting to me if they are! This would mean that as the box was moving right, I would ignore the second contact point of double position, effectively ignoring the upper left corner of all oncoming geometries. The reverse would work for moving left. If this works, it would solve a bug that has plagued me for a long time!
Feb 19, 2009 at 4:19 PM
I've poked around my surface geometries and the physics simulator and I can't find any contact lists outside of the OnCollide Handler.
Is the contact list limited to the OnCollide Event Handler?

The way I envision it, each Geom has a contact list, and they show up in the simulator view as the green dots around each Geom. Is the contact list only the points that are colliding (red in the simulator view), all the points for both colliding Geoms(green dots in the simulator), or is the contact list a list of all contact points of all geometries in the simulator?

How can I access the lists outside of the OnCollide event?

Any help would be awesome, thanks!
Feb 19, 2009 at 6:25 PM
Do you have a simple sample to demonstrate this? I know that this can happens, but I would like to see if there is an easier method tha beginning to edit the FP source code to ignore contacts.
Feb 19, 2009 at 11:25 PM
I edited the Demo3Screen of the Simple Samples Project (static bodies demo) and changed the load obstacles function to this:

public void LoadObstacles()
            _obstacleTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 50, 50, Color.White,
            _obstacleOrigin = new Vector2(_obstacleTexture.Width / 2f, _obstacleTexture.Height / 2f);

            _obstacleBody = new Body[40];
            _obstacleGeom = new Geom[40];
            int xPosition = -500;
            for (int i = 0; i < _obstacleBody.Length; i++)
                _obstacleBody[i] = BodyFactory.Instance.CreateRectangleBody(PhysicsSimulator, 50, 50, 1);
                _obstacleBody[i].IsStatic = true;

                if (i == 0)
                    _obstacleGeom[i] = GeomFactory.Instance.CreateRectangleGeom(PhysicsSimulator, _obstacleBody[i], 50,
                    _obstacleGeom[i].RestitutionCoefficient = .2f;
                    _obstacleGeom[i].FrictionCoefficient = .2f;
                    _obstacleGeom[i] = GeomFactory.Instance.CreateGeom(PhysicsSimulator, _obstacleBody[i],
                if (i == 20)
                    xPosition = -500;
                if(i < 20)
                    _obstacleBody[i].Position = ScreenManager.ScreenCenter + new Vector2(xPosition, 200);
                    _obstacleBody[i].Position = ScreenManager.ScreenCenter + new Vector2(xPosition/2, -200);
                xPosition += 50;

The top level has overlapping geometries, and the bottom level has geometries lined up adjacently. If you move the agent along the surface of the layers, you'll see the effect, especially if you are moving in one direction and then start moving in the other. Overlapping geometries has this phenomenon much more often.

Feb 26, 2009 at 4:09 AM
Youtube Link

Sorry for the poor quality, as it was filmed off my webcam
Mar 5, 2009 at 3:01 AM
Sorry for bugging you guys. If you follow the youtube link I posted, it shows the problem. Is anyone interested or looking into it?
Mar 5, 2009 at 2:03 PM
Edited Mar 5, 2009 at 2:08 PM
Sorry I haven't answered lately, I'm quite busy and puzzled about this "problem". I will contact Jeff to see what he has to say. Will reply once I have more on this.

EDIT: Have you tried with a simple rectangle instead of the agent (from the demos)? I'm not sure where I see the jumping in the video as it might just be small amounts of impulse from the collisions (after the agent has been in the air).
Mar 5, 2009 at 2:24 PM
Oh, did not see your sample code.

Anyway, just send Jeff an email. I hope he has some answers.
Mar 6, 2009 at 3:07 AM
Edited Mar 6, 2009 at 3:09 AM
Hey genbox, thanks for the reply!

The agent in the video is simply moving left and right. I never direct it explicitly into the air. I've tried it with a simple rectangle and the same phenomenon occurs. Hopefully we can figure it out!

The rectangle in question is from a game I just released, Super Comrade Oriam.
You can see a demo video of it here:

You guys should try it out!
Mar 8, 2009 at 7:33 AM
I have a theory about why this happens: each update, the bodies interpenetrate a little and get corrected by the collision algorithms. When this happens near an edge, the geom accidentally catches the corner of the next object and gets pushed up in the air. The only way i can figure out how to solve this is to sort the collision checking order by proximity (so that the pair of objects that are closest are collision processed first).