I've got a player object that has a Rigidbody2D and CircleCollider2d attached to it, and I'm trying to make it move across a large field of tiles, each exactly next to one another and each identical in size. For some reason, the player object occasionally gets stuck on what looks to be points between tiles. Any ideas on why this is happening, or what I can do to fix it? Thanks!
1 Answer
Yeah, what is happening is numerical error is getting your Collider stuck. It's especially bad with AABBs. Basically you're catching a tiny edge between the two blocks you are walking on. This is usually not a problem with games that represent cubes in a grid, as the cubes are implicit geometry in this way. However in Unity you're using a full rigid body engine, and this problem arises.
Things you might try would be to lower friction, not set the position of your player but only update it's velocity (let the physics inside Unity integrate your velocity), don't apply gravity to the player if it is in a "grounded" state. You can try to "merge" many cubes that lay within the same plane and form one giant rectangle, this way the player does not walk over tiny gaps at all.
There's a lot of specific solutions if you have access to the physics engine source (that I am not mentioning), but someone else might know some Unity specifics. I myself have not used Unity.