简体   繁体   English

如何找到 position 用于旋转和非旋转物体的碰撞检测?

[英]How to find position for collision detection with rotated and non rotated objects?

https://editor.p5js.org/bigboss01/sketches/OZLv0TPBn https://editor.p5js.org/bigboss01/sketches/OZLv0TPBn

This sketch illustrates the problem I'm having.这张草图说明了我遇到的问题。 I'd like to check the intersection of the arrowhead and the rectangle, but because the arrowhead is in a rotated space, it does not register the intersection appropriately.我想检查箭头和矩形的交点,但由于箭头在旋转空间中,它没有适当地注册交点。

I've seen this great tutorial on the separating axis theorem: https://dyn4j.org/2010/01/sat/ , but I would appreciate some help connecting the dots as I don't fully understand how to implement this solution.我已经看过这个关于分离轴定理的精彩教程: https://dyn4j.org/2010/01/sat/ ,但我希望能得到一些帮助,因为我不完全理解如何实现这个解决方案。 I found this library , but I would appreciate it if someone knew of a simpler way of doing this, as this seems like a fairly basic problem.我找到了这个库,但如果有人知道这样做的更简单方法,我将不胜感激,因为这似乎是一个相当基本的问题。

The problem I'm trying to solve is in this sketch (a lot more code here, skip to this.update() in the rocket object for collision logic) that is from this tutorial by Daniel Shiffman , his version is here , whose sketch does not seem to be having the same problem- my rockets do not get stuck in the bar, nor do they always register arrival to the target.我要解决的问题在这个草图中(这里有更多代码,跳到火箭 object 中的 this.update() 用于碰撞逻辑)来自Daniel Shiffman 的本教程,他的版本在这里,他的草图似乎没有同样的问题——我的火箭没有卡在酒吧里,也没有总是登记到达目标。

I just made a sketch for this.我只是为此做了一个草图

No idea if it's the best way to do this, but it works for me.不知道这是否是最好的方法,但它对我有用。

Also Dan has a video on the xSpeed = cos(a) * r formula, it should be something like "polar to cartesian coordinates", or smth like that. Dan 也有关于xSpeed = cos(a) * r公式的视频,它应该类似于“极坐标到笛卡尔坐标”,或者类似的东西。

Also when you have an x (x + xSpeed,!!) you can use a "point-rect collision thingy", i just check if(y > 300)此外,当您有 x (x + xSpeed,!!) 时,您可以使用“点-矩形碰撞”,我只检查if(y > 300)

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

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