Jan 23, 2010 at 1:35 AM
Edited Jan 23, 2010 at 1:37 AM
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: