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

Rolling platformer bugs?

Jun 23, 2010 at 8:31 PM
Hello, I'm working on a platformer where the main character is a circular rock, and I move it by ApplyTorque. It jumps using ApplyImpulse. The problem is, when it is moving on a long platform and it starts to accelerate, it will randomly start hopping a little bit off of the ground. Also, when it is moving fast and I press the jump button, the rock barely goes high at all. See this video: You can see the rock randomly starts to hop up when rolling fast. In the video, you can't really see a good example of the jumping bug, but I do jump towards the end. Any ideas on how to optimize my code so that the rock doesn't randomly hop up, and so it jumps at a constant height no matter what? Thanks.
Jun 24, 2010 at 6:07 AM
Edited Jun 24, 2010 at 10:58 AM

Is this Farseer 2 or 3? If it is FP3 make sure you are using a CircleShape instead of a PolygonShape. If it is FP2 this is a problem that happens because the shape is not 100 % round, but an approximation, and I don't think you can really get around that.

Other things you can do to reduce the bouncing is setting the Restitution of the ground and the ball to 0, and seeing if that helps.

For the jumping try using ApplyForce instead, I can't remember which worked best for me but I spent a while experimenting between the 2. Also make sure the impulse/force you are applying is in the correct direction (ie: expecting a world direction but you're passing a local direction)

EDIT (in reply to sonic): I'm not actually a real developer, I just try and help with the samples! :D

Jun 24, 2010 at 6:09 AM
Edited Jun 24, 2010 at 6:11 AM

First off what version of Farseer are you using? If it is 2.1.x, it doesn't have perfect circles. It's just a polygon with MANY line segments and that can cause it to bounce up. I don't think it will be that big of a problem though from what I saw. As for your jumping, I have no clue what your jumping code is but I am going to make an assumption. Whatever you are doing to check when you can jump is being allowed to happen before your character is completely on the ground. That isn't a problem but you will want to clear the linear velocity on the y value of the main character and then apply impulse. See if the character is still even a LITTLE bit in the air, he will have a lot of momentum downwards. The apply impulse will make the momentum move upwards but not as much if there was no momentum to begin with. Just do:


body.LinearVelocity = new Vector(body.LinearVelocity.X, 0);
body.ApplyImpulse(new Vector2(0, -whatever);


Hope that helped!

UPDATE! Developer beat me to it lol. I would follow what he has to say before mine since he understands the engine better than I do.