- Home /
How to check if a polygon fits in specific 2D spot?
I am trying to check if a polygon (the shapes change case-by-case) would be able to fit in specific coordinates in a 2D space before it is moved there.
All the objects have a polygon collider. I have been trying to solve it by copying the polygon collider that the shape-to-be-placed has into an invisible object and placing that object to the coordinates. This part works great. But I am having issues checking if the invisible object is colliding with the existing objects. I have had some luck using bounds.Intersect like this:
if (InvisibleCollider.bounds.Intersects(ExistingCollider.bounds))
{
//Do stuff
}
But the issue is that it is detecting false positives outside the range of the polygon. I assume it creates boxes for checking that are bigger than the outlines. Is there a more exact way to check for collision?
I have also tried collider.IsTouching and collider.isTouchingLayers without any success. collider.OverlapCollider is giving some results, but weirdly it is not detecting all of the obstacles, even if they are all identical.
How would you solve this issue?
Your answer
Follow this Question
Related Questions
How to optimize a lot of colliders? 1 Answer
Block Game Object interaction with another Game Object with kinematic active 0 Answers
Unity 2D game: all colliders not working 3 Answers
How can i compare Text string from multiple child Text objects? 1 Answer
OnCollisionEnter2D is not working when an object tagged "Enemy" is not present in the game. 0 Answers