Search code examples
c#unity-game-enginecollider

2D unity platform game, conflict with Tilemap colliders


I'm trying to create a platform game, watching videos and tutorials I see that they use the Tile Palette option very frequently.

When creating the 2D Tilemap Collider, each square has its collider, and I guess that makes it consume a lot of resources, so to solve that I create a 2D Composite collider. The problem is when the player collides with the collider of a vertical wall, causing the player's rigidBody.velocity.y to add force and that doesn't allow me to execute the jump.

https://clipchamp.com/watch/nFKCJOv7DEX Here you can see under the scene of the game the debug.log that ends up showing me a speed to the Y axis This project would be for android, and I would like to optimize it as much as possible. Do you have any idea so that in that collision I do not add force Y?

I have tried to change the speed in an onColliderStay2d and put the vertical tilemaps with another tag to differentiate them from the ground, but nothing.


Solution

  • Instead of checking your y velocity to see if you are grounded or not I recommend just making a rectangular area under your player character and check if it overlaps with the ground using Physics2D.OverlapArea. It's way less error prone.

    Also, just because composite collider creates less shapes than tilemap collider doesn't mean it is less performant, the physics system doesn't iterate them one by one. Do yourself a favor and just use the tilemap collider instead.