- Home /
"Ghost" collision in 2D physics game
I'm making a 2D game using the Physics 2D engine in Unity. The player does not control any character directly, but can change the direction of gravity to either up, down, left or right. Initial gravity direction is down.
In the attached example below the blue box standing on platform 1 is a Rigidbody2D of body type Dynamic and with Collision Detection set to Continuous, while all other objects in the scene are static BoxCollider2D platforms. When the player changes the gravity direction to right, I'd expect the blue box to fall all the way to the wall at the far right, but sometimes it happens that it bounces off the corner of platform 2 (the red circle). Platform 1 and 2 are of course exactly the same height and in the exact same Y position.
Can anyone provide any insight into why this is happening and what can be done to avoid this faulty collision detection? I've been playing around with all Physics 2D settings under Project Settings, but nothing seems to solve the issue. Also haven't been able to find similar questions with any solutions in the forum. Any help much appreciated!
$$anonymous$$aybe a floating point issue, with your bottom side and that platform's surface using "the same" y-coordinate.
This also happens when folks use character controllers with box colliders, the corners get stuck on the ground for what I assume is the same reason. You could try replacing that single box collider with several stubby capsule colliders.
That's an interesting idea... I tried replacing the box collider with several capsule colliders, which then gives the square small rounded corners depending on the size of the capsule colliders. Unfortunately it doesn't remove the unwanted collection detection, it just makes the square bounce off the corner in a slightly different way because of the rounded corners.
bump, I'm having this same issue myself. I've looked around and it's suggested to use Edge Colliders 2d, but I'm using a tilemap 2d with a composite 2d. I'd like to keep using the composite 2d if I can get a work around for this issue,bump
Your answer
Follow this Question
Related Questions
How to make a 2D physical movement like this ? 0 Answers
Where is mass center of Rigidbody2D placed? 1 Answer
Weird collision 2D problem? 0 Answers
Checking for Colliders with Physics2D.OverlapBoxAll Won't Work? 0 Answers
2D paper plane physics 0 Answers