Hi guys!
I have 2 Objects with box collider and rigidbody attached. I use standard asset script: DragRigidbody.js to drag Object1 to move to collide to Object2. But the function OnCollisionEnter never be called. What I was wrong about?
function OnCollisionEnter(collision : Collision)
{
Debug.Log(“Collision Entered”);
}
Metylbk, i think you must add a condition event :
function OnCollisionEnter (collision : collision){
if (collision.gameObject.name == "the object to hit to");
Debug.Log("Collision Entered");
}
}
doesn’t work for me neither, even with the condition
function OnCollisionEnter(collision:Collision){
if(collision.gameObject.name==“NME”){
Debug.Log(“Hit”);
Destroy(gameObject);
}
}
the script is attached to an instantiated object (bullet) but it doesn’t work
guys… take a look to this video
http://www.unity3dstudent.com/2010/07/beginner-b01-basic-collision-detection/
yeah i ve seen it, i got it right with this one :onTriggerEnter, the trick was to have only one trigger checkbox checked
http://www.unity3dstudent.com/2010/07/beginner-b13-trigger-collision-detection/
but for OnCollisionEnter, i can have it right only if the collisioner is not dynamicaly instantiated.(instead of my bullets)
Thanks Mig. It worked!
Sorry to bump this post but I have the same problem, and I found that it cannot work on dynamically instantiated objects. Help on a workaround?
Thanks!
friend limdingwen
can you cut a screenshots?
Its just not working, even if I have a collider set to trigger -.-
function OnCollisionEnter(theCollision : Collision){
if(theCollision.gameObject.name == “Cube”){
Debug.Log(“it works”);
}
}
I had the same problem, if you use 2d objects use OnCollision2D function. Let me know if that solved your problem
Just in case someone else comes across this, the 2D method is
OnCollisionEnter2D not OnCollision2D (as of 5.4)