平台游戏的 Box2D 和类声音物理

发布于 2024-09-12 17:09:31 字数 433 浏览 7 评论 0原文

我正在开发一款使用 Box2D 和 cocos2D 的 iPhone 平台游戏。

我正在尝试找出一种方法来为我的受控角色创建与 Sonic the Hedgehog 游戏中类似的行为,但保持使用 Box2D 物理库,因为我希望射弹和一些关卡对象的行为符合现实物理,以及涉及受控角色的某些情况(跳跃、撞向物体等)。

我遇到的主要问题是在经过凸曲线时将角色保持在地面上,并保持与地面的接触感,直到与地面保持相当大的距离。我只希望角色在地面上时对左右命令做出反应,但当我经过轻微的曲线时,我的形状往往会离开地面,这样反应时间会短暂延迟,直到重新建立联系。视觉上没有分离,但它足够大,足以改变是否在地面上的状态。此外,角色并没有按照我想要的方式“拥抱”更大的曲线。

我尝试过在地面上施加额外的向下的力,但对于较大的曲线来说,它的工作速度不够快,并且力量足够大,无法有效干扰角色的常规运动。对这些问题有什么想法吗?

I'm working on a platformer for the iPhone that is using Box2D and cocos2D.

I'm trying to figure out a way to create similar behavior for my controlled character as is found in the Sonic the Hedgehog games, but maintain use of the Box2D physics library as I want projectiles and some level objects to behave according to realistic physics, along with certain situations involving the controlled character (jumping, barreling into objects, etc.).

The main issues that I'm running into are keeping the character on the ground when going over convex curves and maintaining a sense of contact with the ground until a significant distance from it is achieved. I only want the character to react to left and right commands when on the ground, but my shape tends to leave the ground when going over slight curves such that reaction time is delayed briefly until contact us reestablished. Visually there is no separation, but it's big enough to change the state of being on the ground or not. Also, the character does not "hug" bigger curves the way I would like.

I've tried exerting an additional downward force when on the ground, but it doesn't work quickly enough for bigger curves, and large enough forces to be effective interfere with the regular movement of the character. Any thoughts on these issues?

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

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

发布评论

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

评论(1

眼泪也成诗 2024-09-19 17:09:31

根据我的经验,要获得真正的类似控制台的感觉需要您创建不切实际的物理效果,尤其是对于玩家角色。

我相信在 box2d 中你可以使用脉冲来破解运动系统,同时仍然可以访问碰撞检测。要么就是这样,要么让你的角色成为一个不移动的物体,然后你自己做运动。我忘记哪个似乎对我有用。已经几个月了;)我相信在某些情况下我还对 y 轴上的向量进行了一些无效处理以修复错误(斜率?)。

如果您的运动在一般情况下工作正常,那么您可以在与曲线接触地面时进行运动作为特殊情况,在这种情况下您自己处理物理,并且仅在现实世界中进行碰撞检测。

另一种选择是让大多数对象使用“假”物理,并仅使用 box2d 进行碰撞检测或“真实”对象。

In my experience, getting true console-like feeling in requires you to create unrealistic physics, for player characters especially.

I believe in box2d you could use impulses to hack the movement system, while still having access to collision detection. It was either that, or making your character a non-moving object, and doing the movement yourself. I forget which seemed to work for me. It's been a few months ;) I believe I also did some nullifying of vectors on the y axis in some cases to fix bugs (slopes?).

If your movement is working properly for the general case, you could make movement when in ground contact with a curve be a special case, where you handle the physics yourself, and only hang out in the real world for collision detection.

Another option is to make most objects use "fake" physics, and use box2d only for collision detection, or for "realistic" objects.

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