Player velocity.y changes when running horizontally over a composite collider 2D?

So I have a tile map, with tiles. I added a tile Collider 2D and a Composite Collider 2D to the tile map. Everything was working perfectly, until i noticed i couldn’t jump. My jump code is based on the player velocity.y == 0, and running horizontally on the composite collider changes the player velocity.y, even though running on a box collider would not. I am very confused. Any help would be greatly appreciated!


In the picture the player is only running horizontally, no code is changing the velocity.y

Turns out that the composite collider applies a little up force to make objects compensate the gaps (Which are unperceptible) between tiles, just add a little velocity threshold to your player’s script like this and it will be just fine
192367-imagen-2022-02-08-123630.png

So, I found a solution for myself, hopefully it’ll be useful for whoever else needs a solution. It got really weird.


First of all, my player was getting stuck on the corners of the tiles in my tilemap, so I added the CompositeCollider2D and made sure my TilemapCollider2D had “Used By Composite” checked.


After this I started getting this issue, my player was unable to jump because I first check if the velocity is close to zero using Mathf.Approximately(). But my rigidbody2d.velocity.y was being set to a strange number every time I would move, I could jump if I stood still though.

My solution to this was to set the Offset Distance on the CompositeCollider2D to 0.


This mostly worked, until I started using the Fill Bucket for the Tile Palette. Any tiles spawned in with the Fill Bucket would still result in this issue occuring. I simply erased those tiles and painted them using the brush instead.


Like I said, it got weird.
Hopefully this helps someone!