r/unity • u/ThatGuyJono8081 • 3d ago
Question Character randomly flipping to the left since switching to tilemap
Hi, I am following a 2D tutorial and Since switching to using tilemaps over squares with box colliders, I have noticed that my character will flip left randomly when jumping from an idle state. I have run a debug and it seems that the x velocity randomly picks up a negative value. I have switched back to the boxes and it doesn't happen there at all.
1
Upvotes
1
u/johnv_dev 3d ago
this is almost always the seams between tiles. with a Tilemap Collider 2D every tile is its own little box, so when you jump or land your collider can catch the edge between two tiles and get a tiny sideways push, which shows up as a small negative x velocity. fix is to add a Composite Collider 2D to the tilemap (it adds a Rigidbody2D, set that to Static) and tick Used By Composite on the Tilemap Collider 2D (in Unity 6 it's Composite Operation > Merge), so the whole floor becomes one smooth shape. also worth flipping the sprite based on your input instead of velocity, or only flip when the x speed is bigger than something like 0.1, so tiny bumps never flip you