- Home /
Box Collider 2D colliding when not supposed to
Hi!
I am making a kind of 2D endless runner / infinite runner game and creating new platforms on the go (these platforms interact with the player with a boxCollider2D). These platforms are connected so they form one long platform. Although they are all on the same y-level, sometimes my player gets caught on the transition of one platform to the next (so on the side of the next platform), quite randomly. They align perfectly. Any tips on how to prevent this?
additional info: platforms are 1x25 meters long, a new one is created at the position.x of the previous one + 25, with equal position.y. The player runs with speed 10 meters/s
Answer by Geejayz · Mar 25, 2018 at 11:19 AM
Hi,
I had this same issue a few days ago. Although I had used the snapping tools and key 'V' to select the corner of a sprite so I could line it up with the one beside it, when I zoomed in really close there sometimes were slight differences in the height of the box colliders.
There are a number of ways to resolve it and you should look at the following links for more detail;
https://answers.unity.com/questions/1066094/sprite-with-box-collider-gets-stuck-on-nothing.html
...
http://forum.unity3d.com/threads/2d-jump-and-run.350872/#post-2272386
...
http://answers.unity3d.com/questions/607080/colliders-2d-apparently-touch-each-other-even-if-t.html
The simple option may be to make the collider on your moving character's feet be a circle collider and check the 'freeze rotation' check box in the constraints section of your character's rigidbody.
I resolved my issue by using the Edge Colliders on the floor pieces instead of the BoxColliders.
Hope that all makes sense.