This project has moved. For the latest updates, please go here.

Issue with IgnoreGravity

Topics: User Forum
Feb 18, 2010 at 12:50 AM

Hey guys.  I'm noticing a weird problem with gravity.  I'm implementing ladders in my game, and as soon as I start climbing a ladder I disable gravity on the player body.  This is met with weird results.  Say I jump onto the ladder and grab it, gravity continues to press down on the player body even though IgnoreGravity is true.  The only way I can really stop gravity is if I disable the body altogether, but when I reenable the body all of the residual gravity force kicks in

I tried to emulate this as simply as possible.

        public void Test()
            body.IgnoreGravity = true;
            body.Enabled = !body.Enabled;


This little bit of code does the same thing.  If I jump and call the method, I will freeze in the air and not drop.  But the second I call the method again, and simply reenable the body without setting IgnoreGravity to false, my body comes crashing down.

Is there any way to simply cancel out all backed up gravity forces?

Feb 18, 2010 at 1:01 AM

Funny, it's always easier to find the answer after you post the question.

If anyone ever runs into this same issue, just call body.LinearVelocity = Vector2.Zero;