良好的 2D 碰撞响应参考

发布于 2024-09-09 04:31:07 字数 297 浏览 3 评论 0 原文

嘿,我目前正在寻找在 2D 视频游戏中实现碰撞响应的各种方法,类似于本教程 Metanet 有: N 教程 我希望在 XNA 中实现一些东西,但任何语言都可以。我对以编程方式实现比实际理论更感兴趣。我更喜欢更多适合初学者的材料,但我也欢迎更多高级主题。

那么有人可以推荐一些好的 2D 碰撞响应文章/书籍吗?

(PS:我对响应比检测更感兴趣)

Hey, I'm currently looking for various methods of implementing collision response in 2D video games, something similar to this tutorial Metanet has: N Tutorial I'm looking to implement something in XNA, but any language would be fine. I'm more interested in implementing programmatically than actual theory. I'd prefer more beginner friendly material, but I do welcome more advance topics.

So could someone suggest some good 2D collision response articles/books?

(PS: I'm more interested in response than detection)

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

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

发布评论

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

评论(7

咋地 2024-09-16 04:31:07

您已经提到的 N 教程 是一个很好的入门资源。我还推荐这篇非常好的文章2D 多边形碰撞检测。它附带了一个很棒的 C# 实现和使用分离轴定理进行多边形碰撞检测的示例,并更好地解释了一些概念。

至于对碰撞的响应,这取决于具体情况。对于游戏,您可能需要根据当前速度检查可能的碰撞,然后只需调整实际速度即可防止碰撞。您还可以实现某种“反弹”效果。在任何情况下,它都可能会调整物体的速度和方向。

您可以使用分离轴定理进行碰撞检测,还可以使用多边形投影来查找特定轴上到目标的距离。 (大多数时候是你移动的向量)。

The N tutorial that you mentioned already is a great resource to start with. I also recommend the very good article 2D Polygon Collision Detection. It comes with a great C# implementation and example for polygon collision detection using the Separating Axis Theorem and explains some of the concepts better.

As far as responding to a collision is concerned it depends on the scenario. For games you might want to check for a possible collision based on the current velocity and then simply adjust the actual velocity to prevent collision. You could also implement some sort of 'bounce' effect. In any case it will likely be adjusting both the velocity and direction of the object.

You can use the Separating Axis Theorem to do the collision detection and also use polygon projection to find the distance to the target on a specific axis. (most of the time the vector on which you move).

说谎友 2024-09-16 04:31:07

我真的很喜欢这个,它一周前刚到,除了相对论效应之外,它还有你想要的一切:

http://www.amazon.com/Physics-Game-Programmers-Grant-Palmer/dp/159059472X

I really like this one, it just arrived a week ago and it's everything you could want short of doing relativistic effects:

http://www.amazon.com/Physics-Game-Programmers-Grant-Palmer/dp/159059472X

笔落惊风雨 2024-09-16 04:31:07

如果您想要碰撞响应的基本答案,这里是:

for each pair of objects that collide
    ask gently to the collision detection lib their interpenetration distance
    Apply an impulse (i.e. a force in the duration of the frame) to both objects :
        force proportional to penetration depth (you will have to tune the coef by hand)
        direction : perpendicular to the collision normal.
        application point : the collision point (approximately, since it s not a point anymore but a volume)
integrate (Euler, Verlet, )\

If you want a basic answer for collision response, here it is :

for each pair of objects that collide
    ask gently to the collision detection lib their interpenetration distance
    Apply an impulse (i.e. a force in the duration of the frame) to both objects :
        force proportional to penetration depth (you will have to tune the coef by hand)
        direction : perpendicular to the collision normal.
        application point : the collision point (approximately, since it s not a point anymore but a volume)
integrate (Euler, Verlet, )\
过气美图社 2024-09-16 04:31:07

您需要多少细节?回答其中一些问题将帮助您消除不能满足您需要的软件包。

您需要担心对象旋转吗?然后您需要关注杠杆臂、角动量、惯性矩和扭矩。

不用担心变形吗?然后,您需要进行有限元分析、应力/应变等——描述物体内部如何响应外力。

摩擦效应又如何呢?然后您需要摩擦系数,或者可能需要空气阻力的速度模型。

引力效应?电磁效应?其他势力?

How much detail do you need? Answering some of these questions would help you eliminate packages that don't do what you need.

Do you have to worry about object rotation? Then you need to be concerned about lever arms, angular momentum, moments of inertia, and torques.

Do you have to worry about deformation? Then you need to get into finite element analysis, stress/strain, etc. -- something that describes how the objects respond internally to external forces.

What about frictional effects? Then you'll need coefficients of friction, or possibly velocity models for air resistance.

Gravitational effects? Electromagnetic effects? Other forces?

红墙和绿瓦 2024-09-16 04:31:07

我也在寻找相同的信息,最有用的
到目前为止我发现

http://www.myphysicalslab.com/collision.html

更糟糕对我来说,这就是
无摩擦(切向碰撞冲量
只是正常的冲动)我认为
这样的摩擦冲动会更好,但仍然
没有找到如何正确实施的教程

I was searching for same info too, The most usable
thing i found so far was

http://www.myphysicslab.com/collision.html

the worse thing here for me is tahat this is
withoout friction (tangent collision impulse
only normal impulse) and I think the one with
such friction impulse would be better but still
not found a tutorial how to correctly implement
that

心作怪 2024-09-16 04:31:07

物理引擎非常复杂。使用现有的会更好。

  • Farseer(C#,源自旧版本的 Box2D)。
  • Box2d(C++,它具有 .NET 绑定)
  • Chipmunk (C,我不认为它有 C# 端口,但你可以制作一个)。

如果您想在游戏中使用物理,请使用 Farseer 或 Box2D 绑定。如果您想学习物理学,请考虑制作 Box2D 或 Chipmunk 的 C# 端口。如果您只是好奇,他们所有的代码都是开源的。

Physics engines are very complicated. You would be much better off using an existing one.

  • Farseer (C#, derived from an older version of Box2D).
  • Box2d (C++, It has .NET bindings)
  • Chipmunk (C, I don't think it has a C# port, but you could make one).

If you want to use physics in your game, use Farseer, or a Box2D bindings. If you want to learn about physics, consider making C# port of Box2D, or Chipmunk. If you are just curious, all of their code is open source.

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