简体   繁体   English

Xna碰撞墙2D

[英]Xna Collision with wall 2D

场景草图

Okay so I have been checking on the internet for an answer to my (some may say simple) collision detection problem. 好吧,所以我一直在互联网上检查我的碰撞检测问题的答案(有人可能说很简单)。 I have a car and I essentially want it not to drive through a wall or get stuck in it. 我有一辆汽车,我本质上希望它不要穿过墙壁或卡在其中。 I have tried to split the wall into four rectangles representing the four edges however it causes the car to move around in a very buggy manner. 我试图将墙壁分成代表四个边缘的四个矩形,但是这会使汽车以非常有故障的方式移动。

Could someone tell me where i could find information or show me how to resolve the collision of a rectangular car with a wall as shown in the diagram? 有人可以告诉我在哪里可以找到信息,或者告诉我如何解决如图所示的矩形汽车与墙的碰撞? I want the car to carry on moving in a direction that does not cause it to go through the wall but like you normally would around it or away. 我希望汽车继续前进,其方向不会使它穿过墙壁,而是像您通常会绕过墙壁或离开墙壁一样。

Look into the separating axis theorem . 查看分离轴定理

You should really read this tutorial from the developers of N+. 您应该真正从N +开发人员那里阅读本教程 It has several interactive demonstrations so you can see the concepts that they describe. 它具有多个交互式演示,因此您可以看到它们描述的概念。

AABB

The car is able to hit the sides of the wall when: 在以下情况下,汽车能够撞到墙壁的侧面:

CarYT > WallYB && CarYB < WallYT

If that's true it hits the left side when: 如果是这样,则在以下情况下会触及左侧:

CarXL < WallXL && CarXR >= WallXL

The other cases are similar. 其他情况相似。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM