开发者

Objects that defy gravity but collide with others in Box2D. How?

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 开发者_JS百科force equal to gravity on these objects all the time. Any better or simpler approaches? Will static bodies help?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜