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

Strange behavior

Topics: User Forum
Jun 18, 2009 at 9:48 PM


Running this code makes rectBody (Black) fall in rectBody2 ~on a half.

Body rectBody, rectBody2; PhysicsSimulator sim; public Window1() { InitializeComponent(); int mass = 1; int width1 = 50, height1 = 50; int width2 = 100, height2 = 2; sim = new PhysicsSimulator(new Vector2(0, 100)); rectBody = BodyFactory.Instance.CreateRectangleBody(width1, height1, mass); rectBody2 = BodyFactory.Instance.CreateRectangleBody(width2, height2, mass); Geom rectGeom = GeomFactory.Instance.CreateRectangleGeom(rectBody, width1, height1); Geom rectGeom2 = GeomFactory.Instance.CreateRectangleGeom(rectBody2, width2, height2); rectBody.Position = new Vector2(25, 0); rectBody2.Position = new Vector2(0, height1 + 1); rectBody2.IsStatic = true; rectGeom.RestitutionCoefficient = 0f; rectGeom2.RestitutionCoefficient = 0f; sim.Add(rectBody); sim.Add(rectGeom); sim.Add(rectBody2); sim.Add(rectGeom2); } ///... sim.Update(0.05f); ///...



Jun 18, 2009 at 10:06 PM

The second geometry is too thin. You can't have a geometry of 2 in height. We don't have CCD (continues collision detection) implemented yet and thus you will experience both tunneling problems and unstable collision. Try with a thicker geometry.

Jun 28, 2009 at 10:42 PM

I've experienced the same problem with a ball with radius=32 and blocks with thickness=20.

When the ball has hits a block with a high enough velocity it gets stuck in the middle of the block..

The solution im currently using is to simply run several physics steps with shorter time. Like for instance if the amount of game time was 0.01s i run 10 simulations with 0.001s each.

This makes the collisions much more accurate but when applying a force it has to be increased 10 times to give me the same result.

Is there any better solution for this problem?

Jun 28, 2009 at 11:02 PM

The current solutions is all listed in the manual. A smaller timestep is one of them.

Jun 28, 2009 at 11:53 PM

A solution not listed in the manual is to scale everything in the world to be bigger. However this has a lot of side effects. Drawing will have to be compensated. Some penatration will still not be resolved. Creation of geometries will be much longer as the geometries will be much larger.

If you must have something like you've shown above try doubling all the sizes of your boxs. Then try the test again. It may or may not improve the results. If not try some of the solutions from the manual. If none of these fix your problem you will need to wait for Farseer 3.0