Dealing with collision in a 2D top down game

I think I understand how tilemap collision basics work, what I’m having trouble with is that my player sprite is able to sort of push through the collision boxes a little bit. Which is the white part here because I want to give the “going behind objects” illusion
9101599--1261480--upload_2023-6-23_18-39-0.png
I wonder if it has something to do with the fact that I have my player move with a vector and never check what’s ahead of it


For context my player will be able to get upgrades to increase their move speed so I can’t just increase the collision box size, otherwise the same problem will happen.

If you need more information just ask



For future reference, photographs of code are not a thing.

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: Using code tags properly

You’re mis-using the physics system. Here’s why:

With Physics (or Physics2D), never manipulate the Transform directly. If you manipulate the Transform directly, you are bypassing the physics system and you can reasonably expect glitching and missed collisions and other physics mayhem.

This means you may not change transform.position, transform.rotation, you may not call transform.Translate(), transform.Rotate() or other such methods, and also transform.localScale is off limits. You also cannot set rigidbody.position or rigidbody.rotation directly. These ALL bypass physics.

Always use the .MovePosition() and .MoveRotation() methods on the Rigidbody (or Rigidbody2D) instance in order to move or rotate things. Doing this keeps the physics system informed about what is going on.

1 Like