碰撞时投射物体 [英] Projecting Objects Out Of Collision

查看:83
本文介绍了碰撞时投射物体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一种爱好,我正在开发2D游戏.我已经使用分隔轴方法实现了一些基本的碰撞检测.当两个对象碰撞时,我沿着重叠量最小的轴将其中一个投影出碰撞.

As a hobby, I'm developing a 2D game. I've got some basic collision detection implemented using a separating axis method. When two objects collide, I project one of them out of collision along the axis that has the least amount of overlap.

我遇到的问题是,当对象快速移动时,重叠量最小的轴并不总是正确的方向.我有的最好的例子是当物体由于模拟的重力拉动而向下(沿+ y轴)移动并与靠近边缘"(如悬崖边缘)的环境物体碰撞时.如果物体跌落得足够快,则重叠量最少的轴即为x轴,然后将物体沿x轴侧向推入.

The problem I'm encountering is that when an object is moving fairly quickly the axis that has the least amount of overlap isn't always the correct direction. The best example I have is when an object is moving down (along the + y axis) due to a simulated gravitational pull and collides with an environment object close to an 'edge' (as in the edge of a cliff). If the object was falling quickly enough, the axis with the least amount of overlap winds up being the x-axis, and the object is pushed sideways along the x-axis.

处理快速移动物体的最佳方法是什么?我已经考虑过以较小的增量移动下降的对象,这似乎增加了很多额外的开销.我还考虑过给环境对象一个优先级",以哪个轴投射掉落的对象,但这似乎很杂乱且容易出错.

What is the best way to handle fast moving objects? I've considered moving the falling object in small increments, which seems like it adds a lot of extra overhead. I've also considered giving the environment objects a 'preference' of which axis to project the falling object, but that seems messy and error prone.

是否可以在不增加很多额外开销的情况下做到这一点?

Is there a way to do it without adding a lot of extra overhead?

推荐答案

我终于设法找到一篇不错的文章,描述了扫描测试,以防其他人在同一问题上偶然发现这篇文章.这篇文章有更多内容,但是下面的链接描述了轴对齐的边界框之间的冲突,这就是我正在使用的:

I finally managed to find a good article describing sweep-tests in case someone else stumbles on this post with the same question. The article has more, but the link below describes collision between axis-aligned bounding boxes, which is what I'm using:

链接文本

这篇关于碰撞时投射物体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆