使用位移向量进行 2d 游戏碰撞检测
我正在尝试为我的游戏实现一种使用 2D 坐标(x,y)和四边形(矩形)的碰撞检测算法。我的数学很糟糕,在发表这篇文章之前,我在 stackoverflow 上浏览了解决方案,这让我更加困惑,因为它们堆满了评论,说这不适用于这种情况,或者有比这个更好的算法等等...
我一开始确实设法实现了一个简单的 AABB 碰撞检测和解决算法,但后来意识到,当对象的速度足够高以使其能够逐步穿过对象时,该算法无法检测到情况。
我当前的思维过程是获取旧位置顶点(oldTL
、oldTR
、oldBL
、oldBR
)和新位置顶点定位对象的顶点(newTL
、newTR
、newBL
、newBR
),创建 4 条线段,由两个线段表示点<代码>(旧), (new) 对于每对顶点,并找出它们是否与任何对象上的任何边相交。
我非常迷失,希望能得到任何帮助或反馈......
I am trying to implement a collision detection algorithm for my game that uses 2D coordinates (x, y) and quads (rectangles). I am terrible at maths, and prior to making this post I wandered through solutions on stackoverflow, which have left me even more confused as they were stacked with comments saying this doesn't work for this case, or there's a better algorithm than this one, etc...
I did manage to implement a simple AABB collision detection and resolution algorithm in the beginning but later on realized the algorithm doesn't detect cases when the object's speed is high enough for it to phase through objects.
My current thought process was to grab the old position vertices (oldTL
, oldTR
, oldBL
, oldBR
) and new position vertices (newTL
, newTR
, newBL
, newBR
) of the object, create 4 line segments represented by two points (old), (new)
for each pair of vertices, and find out if they intersect any edges on any objects.
I'm very lost and would appreciate any help or feedback I could get...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论