- Home /
Find next corner of a 2d pollygon collider
I am pretty new to unity/coding and am currently working on a game that requires me to find the corner of a polygon collider. I have had some success with this but am getting thrown by strange cases. I feel this should be fairly simple and I am missing something obvious.
I currently have a collider created from a set of points, I want to find the point after the collision:
so in this example point 3 would be returned.
I initially set this up to check the distance between the collision and each point what worked okay, however I couldnt distinguish between if it returned the point before or after, and I also had cases like this which threw it completely.
Point 3 should still be returned here, but it was returning point 5.
I attempted to solve this by calculating the area between consecutive points and the collision, then taking the pair with the smallest area. This initially worked really well, however I still get cases such as below where the correct pair of points might not be returned.
in the first example sometimes 7 and 8 would return. In the second example sometimes 5 and 6 would.
I feel like im tackling the problem the wrong way and an easier solution exisits. Ideally I would like a solution that would work with both polygoncolliders and edgecolliders. Any point in the right direction would be appreciated, so far my searches have come up empty.
Thanks,
Your answer
Follow this Question
Related Questions
Tile collision by sprite is not accurate with Tilemap Collider 0 Answers
Make 2D projectile collide only from the outside 1 Answer
[2D] Is it possible to create a collider for 2D lights? 0 Answers
2D Getting Arrow to stick to what it has collided with 1 Answer
2D dynamic collider for dynamic shape 0 Answers