ApplyImpulse to Rectangle Body for sidescroller movement, causes rubber band effect

Topics: User Forum
Jan 23, 2010 at 1:35 AM
Edited Jan 23, 2010 at 1:37 AM

Hi everyone,

I've picked up C# and XNA to do a little game programming, and especially since I've heard about Farseer it's been a lot of fun. However, I'm having a bit of an annoying issue.

I have some code that creates a little character who walks around on a platform with a crate on it. Since I've read that it's the optimal solution, I'm controlling movement with Body.ApplyImpulse();. Unfortunately, it seems that once you get running for a little bit and stop, while he slows to a halt as you'd expect him to, the character seems to oscillate back and forth around his final resting point before actually ceasing to move. I've seen some examples in the demos in which objects don't suffer this problem, but I can't seem to tweak the body's properties right to get it to stop moving smoothly.

The code that sets up the physics properties is in the LoadContent() method:

 

fitzgerald.body.LinearDragCoefficient = 1000f;
fitzgerald.Mass = 750;
fitzgerald.geometry.FrictionCoefficient = 0.1f;
fitzgerald.Position = new Vector2(150, 60);

Changing the FrictionCoefficient seems to have little effect, so I'm just leaving it at 0.1f for now. The physics gravity is set to 1000f when I initialize PhysicsSimulator.

Also, through no thought of my own the character will jump higher when you are moving. Is this because somehow the vector of the Body's movement is larger overall when combining the horizontal and veritcal movement of the character? I'm sort of at a loss as to why this is happening, but I was probably going to try to make that happen anyway, so it's not so terrible a thing.

Link to source code and VS2008 project: http://bartnett.com/files/ProjectDaHooch.zip

Coordinator
Jan 23, 2010 at 3:27 AM

Try mimicking the update timings used in the samples. (look at the place where PhysicsSimulator.Update(....) is run). A gravity vector of 1000 is quite a lot and perhaps you should do the physics update a little more often. Updating the physics engine more often (using a smaller timestep in the Update() method) will result in more accurate physics.

Feb 16, 2010 at 7:51 PM

1000 is quite a lot for gravity?  I find myself using 2000 as anything less feels really floaty...