Box2D 中抵抗重力但与其他物体发生碰撞的物体。如何?
这里是 iPhone 游戏开发和 Box2D 的新手。
我正在开发一款游戏,在其中我可以移动(拖动)可能与其他对象碰撞的静止对象。
如何使这些物体在具有重力的 Box2D 世界中静止,同时保持它们与动态物体碰撞的能力?
一个随机的想法是始终对这些物体施加等于重力的力。有更好或更简单的方法吗?静态物体会有帮助吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
静态物体会与动态物体发生碰撞,但不会与其他静态物体发生碰撞。这听起来像是你想要的,但从你的描述中并不清楚所讨论的“其他机构”是什么。
您无法针对每个对象禁用重力;施加与重力相反的力通常会起作用,但由于舍入误差,可能会累积较小的速度。更好的方法是将重力设置为 0,并手动对您想要受重力影响的对象施加重力。
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.