- Home /
Object passes through collider even when isTrigger is turned off.
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!
Answer by UnityCoach · Oct 13, 2018 at 04:45 PM
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.
Yes, Translate works poorly or not at all with physics functions. I'm now using moveposition to move my player and now collision is working fine. Thank you so much for your time!
Answer by ElementalVenom · Oct 13, 2018 at 03:55 PM
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.
Translate works poorly or not at all with physics functions. I'm now using moveposition to move my player and now collision is working fine. Thank you so much for your time!
Your answer
Follow this Question
Related Questions
Rigidbody gets stuck in wall after falling 0 Answers
Sprites collision not working on high speeds 1 Answer
Why can't I destroy this object!? 3 Answers
Collision detection issue 1 Answer