Inverted gravity problem

Discuss issues specific the Java port of Box2D
Posts: 1
Joined: Wed Apr 12, 2017 3:33 am

Inverted gravity problem

Postby jdleung » Wed Apr 12, 2017 3:36 am

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?


Posts: 3
Joined: Sun Apr 23, 2017 7:44 am

Re: Inverted gravity problem

Postby JeneaV » Sun Apr 23, 2017 7:57 am

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?


Return to “Java”

Who is online

Users browsing this forum: No registered users and 2 guests