how to prevent a game object's mesh going through walls or boxes or another meshes

hi guys
i’m new to unity, so my problem maybe is so simple. but as you can see in the attached image, when my character runs toward objects like boxes, than his head is intersecting with the other meshes. I already used collider for both objects. Is there any way to prevent this intersection?

203074-capture.png

On the second image, you can see the issue - your collider is just capsule that does not change its size no matter your animation. There are multiple ways to resolve this:

  1. Add separate colliders of each moving parts of your model.
  2. Add wider collider to the entire model, and configure it to collide specifically with level geometry. Its size should encompass your entire area where animation would happen.
  3. Handle this on the movement logic level - e.g. check by raycast the distance to the wall before the character, and if it is too small, character should simply stop running.

You need collider. Just add capsule collider to player and box collider to that cube object. Done!

Thanks for help!
I didn’t want to use separate and wider collider so last night i ended up with detecting wall and playing stop animation (stop running)
Thanks anyway, your answer was perfect and best, i really appropriate it!