如何根据方向/幅度矢量和碰撞三角形来偏转方向/幅度矢量?

发布于 2024-10-10 03:01:46 字数 172 浏览 1 评论 0原文

所以,我有一个 Triangle->AABB 碰撞算法,并且它返回 AABB 碰撞的三角形。我希望通过三角形的 3 个向量和运动的方向/幅度可以让我确定一个偏转向量,这样当你以一定角度撞到墙上时,你会移动得更慢,具体取决于碰撞的角度,但沿着侧面墙。这将消除粘性碰撞问题,仅在没有碰撞时才移动。任何建议或参考将不胜感激!谢谢。

So, I have a Triangle->AABB collision algorithm and I have it returning the triangle that the AABB collided with. I was hoping with the 3 vectors of the triangle and the direction/magnitude of the movement would let me determine a deflected vector so that when you run against the wall at an angle you move slower, depending on the angle of collision, but along side the wall. This would remove the sticky collision problem with only moving when there is not a collision. Any suggestions or references would be greatly appreciated! Thanks.

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

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

发布评论

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

评论(2

初吻给了烟 2024-10-17 03:01:46

首先,我会将幅度/方向转换为向量(这更方便)。

然后(c++):

float towards=dot(velocity,norm);  // velocity component into triangle
if(towards<0)                      // is moving into triangle
  velocity-=towards*norm;          // remove component

那么它就不能移动到三角形中。根据您的正常情况,towards<0 可能需要反转。有弹簧力将其推出也很好。

First, I would convert magnitude/direction to a vector (it's much more convenient).

Then (c++):

float towards=dot(velocity,norm);  // velocity component into triangle
if(towards<0)                      // is moving into triangle
  velocity-=towards*norm;          // remove component

Then it can't move into the triangle. towards<0 might need to be reversed depending on your normal. It's also nice to have a spring force pushing it out.

木森分化 2024-10-17 03:01:46

移除沿三角形法线的速度分量。

这个想法是,您可以将运动表示为移动“进入”三角形的部分和其余部分(将在垂直方向上)。如果您随后仅与其余部分一起移动,则您将不再通过移动更接近三角形(或更远,但在这种情况下您不应该检测到碰撞)。

在伪代码中:

// v := velocity vector of moving object
// p[3] := points that make up the triangle

triangle_normal = cross(p[2]-p[0], p[1]-p[0])
problematic_v = project(v, onto=triangle_normal)
safe_movement = v - problematic_movement

请注意,这故意不保留运动矢量的大小,因为这样做会让你在直接跑向墙壁时非常快速地沿着墙壁滑动。

有关更多详细信息和一些漂亮的图片,请参阅台球厅课程:快速、准确的碰撞检测Gamasutra 的圆或球体。您没有使用球体,但本质上是在进行完美的塑性碰撞(因为您不会弹跳)。

Remove the component of the velocity along the normal of the triangle.

The idea is that you can represent the movement as the part that's moving "into" the triangle and the remainder (which will be in perpendicular directions). If you then just move with the remainder, you will no longer be getting any closer to the triangle by the movement (or further, but you shouldn't be detecting a collision in that case).

In pseudo-code:

// v := velocity vector of moving object
// p[3] := points that make up the triangle

triangle_normal = cross(p[2]-p[0], p[1]-p[0])
problematic_v = project(v, onto=triangle_normal)
safe_movement = v - problematic_movement

Note that this intentionally doesn't preserve the magnitude of the movement vector, as doing so would make you slide along a wall very quickly when running straight at it.

For more details and some nice pictures, see Pool Hall Lessons: Fast, Accurate Collision Detection Between Circles or Spheres at Gamasutra. You're not using spheres, but you are essentially doing a perfectly plastic (since you don't bounce) collision.

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