I begin with Unity and try to make a quick plateformer 2D.
I move my “player” on multiple tiles and he stuck sometimes in the corner of the next tile. I have see some post with the same problem but never a solution without change the box-collider of my player in circle-collider, and I want keep a box.
@Pob_Fr . I afraid the involvement of circle collider is the most common and correct fix to your problem if you want to use physics to move your player GameObject. You might need some very tricky workaround if you insist on using a box collider on your player GameObject. Is there any reason you must use box collider for your player?
And yes, I want use a box because the player is the a box
I have already try with circle collider but there still little bug. Like the object is “bumping” on angle when is moving.
Oh well, it’s obviously a box shape player, what am I asking .
It really boils down to how you want your games to behave, then implement around it. If you games is a very “boxy” games like shown in your attached picture, then instead of forming your ground with a list of box game object with box colliders, you can consider to form the ground with box game objects (without box collider on each of them) and then create one edge collider / box collider that cover up the group of ground’s gameobject. In this case, you will have a flat surface instead of a bumpy one.
The real problem is not so much the player BoxCollider2D but the construction of a continuous surface using multiple BoxCollider2D. No matter how close you put them, they’re still separate boxes with corners that (due to precision) will cause you to collide with them.
The real solution is to use a single EdgeCollider2D to create a continuous surface and it’s also better for performance. Even using a single BoxCollider2D to cover the surface is better.
If you absolutely must have a collider for each tile on that surface then consider using the EdgeCollider2D with a single edge and increase the Y offset so it sits on ‘top’ of the tile-sprite.
Whilst it’s convenient to associate both a sprite and a collider on a GameObject then copy it everywhere, it’s not the best for the physics system unfortunately.
The smart-sprites will help with this situation in the future.
Note sure what you mean by exact position but all 2D colliders have an offset property (http://docs.unity3d.com/ScriptReference/Collider2D-offset.html) for positioning local to the GameObject its on. The real problem is that if you treat each tile as a GameObject with a collider then you just end-up with lots of single edges rather than a continuous set of edges on one component.
You could put circle colliders on the corners that are slightly outside the interior box collider bounds. That would smooth out inter-tile collision jutter like that.