- Home /
Help with OnCollision
So in my game i needed to detect when a collision happens. I am using a character controller for my character because i use the simple move action. I debugged it and found out that it was not detecting the collision. here is the part of my code that uses the OnCollision and is not working.
function OnCollisionEnter( collision : Collision )
{
Debug.Log("stopped");
moving = false;
downMove = false;
upMove = false;
leftMove = false;
rightMove = false;
}
do you have a rigid body on it or the object you are colliding with?
The two have colliders? The script is on collider object on in a child object? Even if you marks as trigger, the OnTriggerEnter won't trigger?
Answer by MileSplit · Jan 19, 2013 at 10:33 PM
Ok got it i needed to use OnControllerColliderHit
Answer by Anxo · Jan 19, 2013 at 08:47 PM
Check the Unity Documentation for OnCollisionEnter, You need to have a Rigidbody component attached to either object.
http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html
Yah i added rigidbodys to everything and it did not work, i even tryed using OnTriggerEnter. no luck