- Home /
OnCollisionEnter not working!
I'm trying to make a cube destroy when a sphere hits it, and i can't seem to make it work. This is the code i have so far
void OnCollisionEnter(collision : Collision)
{
if ( collision.gameObject.tag == "Sphere" )
{
Destroy(gameObject);
}
}
the sphere is being created each time i press space (like some sort of projectile) and it's moving forward with constant speed, and I'm trying that when it collides with a cube it destroys it.
Are you sure the cloned object has the right tag?
If you put
'Debug.Log("Here: "+collision.gameObject.tag+", "+collision.gameObject.name);'
at the top of OnCollisionEnter(), is the Log() outputting to the console?Do both objects have a colliders?
Are you moving the sphere through physics (AddForce() or setting Rigidbody.velocity)?
I just solved it by changing collision.gameObject.tag to .name and removing the rigidbody from the cube. Thank you!
Your answer
Follow this Question
Related Questions
Jumping while on a collider adds extra force 1 Answer
Which Object Calls OnCollisionEnter()? 3 Answers
Box collide but OnCollisionEnter doesn't work 1 Answer
OnCollision Works for one script but not the other? 2 Answers
Cant get Collisions to work 3 Answers