Page 1 of 1

Inverted gravity problem

Posted: Wed Apr 12, 2017 3:36 am
by jdleung
I'm using jbox2d in Android, I found all the examples on the web have a negative gravity(-9.8), but in my version, I have to set it to a positive value so that body can be pulled down by gravity, a negative value makes it goes upward.and I have to set it bigger than others.

Code: Select all

Vec2 gravity = new Vec2(0, 50f);

Is there any problem with my download version?


Re: Inverted gravity problem

Posted: Sun Apr 23, 2017 7:57 am
by JeneaV
Looks like something is implemented wrong.

Look at this picture below. On the left side you can see that Y axis of box2d world actually is pointing up and the gravity applied on every object have to be negative so

Code: Select all

body.applyForceToCenter(new Vector2(0, -9.8f), false);
will push world objects down.
On the right side you can see that so called processing world (you can think of it as a screen of your device) has it's own Y axis and it points down.

Maybe you have an image in your code that is drawn on the screen but in wrong direction?