- Home /
OnCollisionEnter does not work.
Hey guys I am trying to make it so that once my AI hits an interactive object(couch) then he switches to another waypoint, but nothing happens when my AI hits an object, the function is not being called cause I put a debug right at the beginning. I have the couch tagged as "Interactive" and placed this code on the AI. NOTE: this is a long script, I have set currentWaypoint and randomWaypointRange as ints FYI.
function OnCollisionEnter(other : Collision){
if(other.gameObject.tag == "Interactive"){
Debug.Log("Hit an Object");
currentWaypoint = Random.Range(0,randomWaypointRange);
}
}
Are you even entering the OnCollisionEnter method ? Pu a Debug.Log line before the "if" statement to be sure of that.
No, I put the Debug.Log before the "if" and it didn't show the message.
So the problem is not related with tags (or maybe but we'll see that later ...).
Do you have any collider type attached to the game object that contains this script ?
Ok, and do the other game objects, tagged "Interactive" contain a rigidbody or a collider too ?
Answer by landon912 · Nov 17, 2013 at 04:06 AM
View the bottom of this reference page and make sure the two colliders you want to collide are compatible.
Then once they are colliding correctly make sure that the gameObject is tagged correctly.
Your answer
Follow this Question
Related Questions
how to make object stay destroyed after OnTriggerEnter? 1 Answer
How to use functions between two scripts 2 Answers
Restart this script 3 Answers
Camera Move 1 Answer
How to call a function from a script in another scene 5 Answers