- Home /
Box colliders on a grid. How to prevent unwanted collisions at distance 0?
On a 2D grid of squares (like a chess board), there are some static box colliders (see brown squares in the image) and moving box colliders (chickens) that automatically move either vertically or horizontally at a constant speed. Both the static and moving colliders have the same dimensions (1 x 1).

When the chickens collide with a static box they change direction by turning 90 degrees. If I set the trigger to OnTriggerEnter2D or OnTriggerStay2D they incorrectly collide with static boxes on adjacent rows or columns because the distance between them is 0. If I set the trigger to OnTriggerExit2D, they move slightly too far before triggering the collision, making their next collision incorrect.
How can I change this so that the trigger only occurs when chicken box colliders hit static box colliders in the same row or column when the distance between them is 0?
Your answer