碰撞检测,“推出”的替代方案

发布于 2024-08-28 00:18:49 字数 182 浏览 4 评论 0原文

我正在物理引擎中移动一个角色(椭球体)。移动必须受到静态几何体的约束,但应该在边缘上滑动,这样就不会被卡住。

我当前的方法是将其移动一点,然后将其推出几何体。看起来确实有效,但我认为这主要是因为运气。我担心在某些特殊情况下这种方法会失控。例如,两堵墙不断将角色推向对方的尖角。

“最先进的”游戏引擎如何解决这个问题?

I'm moving a character (ellipsoid) around in my physics engine. The movement must be constrained by the static geometry, but should slide on the edges, so it won't be stuck.

My current approach is to move it a little and then push it back out of the geometry. It seems to work, but I think it's mostly because of luck. I fear there must be some corner cases where this method will go haywire. For example a sharp corner where two walls keeps pushing the character into each other.

How would a "state of the art" game engine solve this?

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

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

发布评论

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

评论(2

变身佩奇 2024-09-04 00:18:49

我还没有开发出最先进的游戏引擎,但我曾经编写过一款赛车游戏,其中通过反转模拟时间并计算边缘交叉的位置来简单地处理碰撞。然后汽车被允许弹回游戏场。处罚是,在汽车停下来之前,控制装置将被禁用。

所以我的建议是,您运行物理引擎来准确计算边缘被击中的位置(可能需要一些非线性方程求解方法),然后更改速度矢量以弹开或跟随边缘。

在防止极端情况的情况下,人们可以始终保留游戏中最后一个有效位置的历史记录以及物理引擎的状态。如果游戏陷入困境,可以从该点开始重新启动模拟,但条件不同(例如向内部参数添加一些随机化)。

I have not developed a state of the art game engine, but I once wrote a racing game where collision was simply handled by reversing the simulation time and calculate where the edge was crossed. Then the car was allowed to bounce back into the game field. The penalty was that the controls was disabled until the car stopped.

So my suggestion is that you run your physics engine to calculate exactly where the edge is hit (it might need some non-linear equation solving approach), then you change your velocity vector to either bounce off or follow the edge.

In the case of protecting against corner cases, one could always keep a history of the last valid position within the game and state of the physics engine. If the game gets stuck, the simulation can be restarted from that point but with a different condition (say by adding some randomization to the internal parameters).

秋千易 2024-09-04 00:18:49

考虑使用第三方物理库,例如 Chipmunk-physicals 或 Box2D。当谈到游戏物理时,除了最基本的东西之外的任何东西都可能非常复杂,并且没有必要重新发明轮子。

通常,您提到的问题是通过确定重叠量、接触点和表面法线(例如,通过使用分离轴定理)来解决的。然后计算并应用脉冲,这会改变对象的速度,以便在下一次迭代中对象以物理上真实的方式分开。

Consider using a 3rd party physics library such as Chipmunk-physics or Box2D. When it comes to game physics, anything beyond the most basic stuff can be quite complex, and there's no need to reinvent the wheel.

Usually the problem you mention is solved by determining the amount of overlap, contact points and surface normals (e.g., by using separating-axis theorem). Then impulses are calculated and applied, which change object velocities, so that in the next iteration the objects are moved apart in a physically realistic way.

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