2
votes

newbie to iPhone game development and Box2D here.

I'm developing a game in which I can move (drag) otherwise stationary objects that can collide with other objects.

How do I make these objects stationary in a Box2D world with gravity while maintaining their ability to collide with dynamic bodies?

One random thought is to exert a force equal to gravity on these objects all the time. Any better or simpler approaches? Will static bodies help?

1

1 Answers

3
votes

Static bodies will collide with dynamic objects but not other static objects. That sounds like what you want, but it's not clear from your description what the "other bodies" in question are.

You cannot disable gravity on a per-object basis; exerting a force equal to the opposite of gravity will usually work but can, due to rounding errors, accumulate small velocities. A better approach is to set gravity to 0 and manually apply a gravitational force on the objects you do want affected by gravity.