- Home /
How to get an accurate collision distance (get closest points on one axis)?
So for my own reasons am making a collision detection system; but am struggling a little bit. Am not interested in angular acceleration and complicated stuff. I just want to get how much distance is left until collision. So I thought getting the closest points (the red ones) and then casting rays would be enough, but then I realized this:
The closest points may not be aligned on the x axis, which leads to different problems. The red point on the rigidbody (the tetris figure) is not at the vertical edge. I Have drawn the brown lines where they should start and end. In this case are the limits of the bounding box, but it may not be that always. Besides that, in the first diagram the blue line is the shortest distance, not the brown. Then instead cast the ray from the red point on the other collider in the opposite direction? No. That doesn´t work either. As shown in the second diagram, that distance may actually be longer. Which would be the best approach to this? I need to get that information before the collision is done.
Edit: I have thought and realized that this problem is caused by the fact that the closest point may be above. Not just like this, but even above the rigidbody. Is there a way of getting the closest points, but aligned on one axis?
since tetro$$anonymous$$os consist of 4 squares each, you could just do a sweep test as far as the next move would go for all 4 locations and let the physix engine provide you the relevant collision points. then you can compare distances of x and y and the closest of both is the one.
Thanks for your answer. I have searched and there´s litte information about sweep tests, but what I understand is that is like casting rays or shapes along the bounding box. So if it´s the x axis, it casts rays along the heigth to the left/ right and gets the closest collision. (Please correct me if am wrong). Besides from that, the tetro$$anonymous$$o was just an example. This is mainly for characters and rigidbodies with irregular forms. How would affect the sweep test in this situation?
if it's getting more complicated than this and even as complicated as a whole character pose you should probably hire at NVidia Physics $$anonymous$$m, because then you're really good at this.
Your answer
Follow this Question
Related Questions
Is there a limit on the distance of raycast? 2 Answers
How do I solve the Box Collider (3D) Edge / Corner Collisions problem? 5 Answers
How to get the center of a CapsuleCast or SphereCast on collision 1 Answer
Detect if a non-trigger collider is inside another collider 1 Answer
Can I implement basic physics on cubes without writing code? 1 Answer