- Home /
Collision Not Working
My player a rigid body controlled using Input is not colliding with an enemy when no keys are pressed. When no keys are pressed enemy simply goes through the player without collision.
The OnCollisionEnter methods only gets called when I'm pressing a key in keyboard:
void OnCollisionEnter(Collision other)
{
if (other.collider.tag == "enemy") {
Die ();
}
}
Player Collision Settings:
Enemy Collision Settings:
We can't see your image, but i think i can guess what your problem is : Do you enemies have rigidbodies or are you moving them with their transform. Because the Physics engine only calculate collisions for rigidbodies, so if you rigidbody doesn't move it shouldn't collide with anything other then an incom$$anonymous$$g rigidbody (wich will wake him up).
Any $$anonymous$$OVING Object that should collide with another collider should have a rigidbody.
Answer by hexagonius · Jun 07, 2017 at 02:49 PM
Move EVERY RIGIDBODY that needs to be moved in FixedUpdate. Use either MovePosition on kinematic Rigidbodies, or change their velocity if not. Any other way bypasses the physics engine.
Your answer
Follow this Question
Related Questions
How to detect collision on only one side of an object? [C#] 4 Answers
Collider with rigidbody does not register collision with terrain 2 Answers
Convert Rigidbody code to CharacterController usable 0 Answers
Rotating player relative to the camera (Unity C#) 1 Answer
Problem with jumping in fps game 1 Answer