如何让移动的物体“粘住”到 box2D 中的静止物体

发布于 2024-09-28 12:51:03 字数 638 浏览 0 评论 0原文

我一直在 iPhone 的 cocos2D 中试验 box2D 示例项目,并且想知道 box2D 是否是合适的引擎,可以在移动对象完成沿某个方向的移动时使移动对象“粘”到静止对象。

这是我想要实现的目标的简化:我有 MovingObject,一个动态刚体,当对其施加足够的力时,它会抵抗重力垂直移动。当 MovingObject 移动时,它可能会与静态对象 StationaryObject 重叠。当重力将 MovingObject 的速度减小到零以致它不再移动时,我希望 MovingObject 仅当它与 StationaryObject 重叠时才保持在原来的位置。如果对象不重叠,则 MovingObject 应开始根据重力向下移回地面。在下降过程中,如果 MovingObject 在任何时候与 StationaryObject 重叠,它应该停止下降并保持在该位置,就像卡在 StationaryObject 上一样。

我能够让 MovingObject 根据我对其施加的力进行移动,但不太确定如何使其停止并在其到达上升顶部后停留在那里(假设它与 StationaryObject 重叠)。

目前,我正在尝试简单的方形/盒子对象,但最终两个 MovingObject StationaryObject 将被定义为非常不同的复杂多边形形状。

预先感谢您为实现这一目标提供的任何见解和/或建议。

I have been experimenting with the box2D sample project within cocos2D for the iPhone and am wondering if box2D is the appropriate engine to use to make a moving object "stick" to a stationary object when the moving object is finished moving in a certain direction.

Here is a simplification of what I am trying to achieve: I have MovingObject, a dynamic rigid body, that moves vertically against gravity when enough force is applied to it. As MovingObject moves, it may overlap a static object, StationaryObject. When gravity diminishes MovingObject's velocity to zero such that it is no longer moving, I would like to have MovingObject remain where it is ONLY if it overlaps StationaryObject. If the object's do not overlap, MovingObject should start to move back down towards the ground per the force of gravity. During that descent, if MovingObject at any time overlaps StationaryObject, it should stop its descent and remain in that location as if it is stuck on StationaryObject.

I am able to get MovingObject to move per the forces I am applying to it, but not really sure how to make it stop and stay there once it reaches the top of its ascent, assuming it is overlapping StationaryObject.

Currently, I am experimenting with simple square/box objects but eventually both MovingObject StationaryObject will be defined as very different complex polygon shapes.

Thanks in advance for any insights and/or suggestions for achieving this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱你不解释 2024-10-05 12:51:03

听起来您想在“上升”时更改用于“移动对象”的夹具类型,然后在“下降”时更改它,以便它做出不同的反应(重叠)。

通过“重叠”,听起来你想在平台游戏(即马里奥兄弟)中实现类似于“单面平台”的东西 - 我建议初学者研究单面平台的解决方案。

Sounds like you'll want to change the type of fixture used for "MovingObject" while it "ascending" and then change it when it is "descending" so that it reacts differently (to overlaps).

by "overlap" it sounds like you want to achieve something similar to "one sided platforms" in a platform game (ie; Mario Bros.) - I would recommend looking into the solutions for one-sided platforms for starters.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文