简体   繁体   中英

Is there a way to achieve change in gravitational pull using box2d?

I am trying to create a scene where first half has gravity from the top and second half has gravity at the bottom.

How do I achieve this in Box2D as I can only define gravity for the whole world. Do I need to split screen into two worlds ?

You would need to set the gravity for the world to zero, and use ApplyForce to each dynamic body individually depending on where it currently is. The magnitude of the force to apply is the mass of the body multiplied by the gravity, and would be applied at the center of mass of the body. More info here: http://www.iforce2d.net/b2dtut/custom-gravity

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM