- Home /
OnCollisionEnter does not work
Hi everyone, I have not so serious problem but I tried almost everything and it does not work. I have a player, This is my player.![alt text][1], and I have a floor object, this is my floor, ![alt text][2] I have the following function in script which is attached to floor
Debug.Log(other.gameObject.name);function OnCollisionEnter(other : Collision){
} my player walks over the floor but it does not write anything in console, I tried many things but I could not fix it, if anyone can please help me. [1]: /storage/temp/6684-player.jpg [2]: /storage/temp/6685-wooden+floor.jpg
Answer by dmg0600 · Sep 19, 2014 at 09:47 AM
You could turn it around and check the collision on the player. To do so add a script to the player like this:
function OnControllerColliderHit (hit : ControllerColliderHit) {
Debug.Log(hit.gameObject.name);
}
Take into account that this way you will be checking if the player has had a collision with the floor instead of checking if the floor has had a collision with the player.
Answer by Lovrenc · Jan 14, 2013 at 12:36 PM
OnCollisionEnter only happens when collision happens but AND it there was no collision inprevious FixedUpdate.
If you want to check if collision is still happening use OnCollisionStay.
Other than that, you dont want to use rigidbody on gameObject that hac character controller. Chose one on another, otherwise wierd thigs are going to be happening.
I changed function OnCollisionEnter with OnCollisionStay but it acts the same as before. and I ramoved rigidbody from player too.
Use CO$$anonymous$$$$anonymous$$ENT to write comments. Do you have gravity on character controller? How are you moving?
Hi there. I am having the same problem too :/
I did some tests on this, using Unity 4.5.2 and it didn't work for me either, when I used the First Person Controller from the Standard Assets for a CharacterController. When I used a Capsule GameObject with a CharacterController component on it, it worked, provided the floor had a Rigidbody on it. $$anonymous$$aybe there's a nasty bug in Unity 4.5.2. So, I'm upgrading to the latest 4.5.4 to see if this behaves properly.
It has to be with the way CharacterControllers are implemented. You should control collisions from them, not from outside the CharacterController. Check my answer below.
Answer by vanshika1012 · Sep 19, 2014 at 01:08 PM
Either use rigid body or use Character controller. Although you can use both at a time but they produce unexpected results.