I have a player that is moved using transform.translate. I want that player to not pass through an enemy. I have added Box Collider 2D and rigidbody2D to both the objects, set it to dynamic and toggled off the isTrigger button and freezed rotation in the z axis. But the player passes right through the enemy. What am I doing wrong? Thank you!
From the docs :
A Kinematic Rigidbody 2D does not
collide with other Kinematic Rigidbody
2Ds or with Static Rigidbody 2Ds; it
only collides with Dynamic Rigidbody
2Ds.
If both the player and enemy are Kinematic, they will go right through each other.
It also says :
Kinematic Rigidbody 2D is designed to
be repositioned explicitly via
Rigidbody2D.MovePosition or
Rigidbody2D.MoveRotation. Use physics
queries to detect collisions, and
scripts to decide where and how the
Rigidbody 2D should move.
Hope this helps.
Firstly make sure your “transform.translate” is in the FixedUpdate method and NOT in the regular Update method. If that doesnt fix it for ya then youll have to add a check to see if there is something there before you transform.translate to the position. In 3D games i do this with Physics.Raycast in the direction im intending to move the transform to see if anything is there but im sure there are better ways to do it in a 2D game.