0
votes

So I've gone through all the similar questions, but have still been unable to make this work. I'm new and getting the hang of collision detection.

I have a sphere prefab and a target prefab. The spheres are being shot at the target. When the sphere collides with the target I want the target (a 3d game object) to get destroyed.

My sphere prefab currently has a sphere collider with isTrigger checked and a rigid body that uses gravity. My target prefab has a box collider with isTrigger unchecked and a rigid body with use gravity and isKinematic unchecked (since I want the targets to just sit on the screen, not fall down).

This is my code on the sphere's script:

 void OnCollisionEnter(Collision collisionInfo) {
     Debug.Log("Detected collision between " + gameObject.name + " and " + collisionInfo.collider.name);
 }
 void OnTriggerEnter(Collider other) {
     Debug.Log("Collided with " + other.gameObject.name);
 }

Neither debug statement is printing out. Any ideas what I'm doing wrong in the editor?

1
Does one of the objects have a rigidbody?Fredrik Schön
What if you uncheck the isTrigger?I.B
I tried unchecking the isTrigger but still doesn't work. Both prefabs have a rigid body (the targets have no gravity)Surz
Collision is also governed by layers. Make sure the layers of the sphere and target are not excluded from collision with each other. Note that even if they are on the same layer, a layer can be excluded from colliding with itself.avariant

1 Answers

1
votes

Take a look at this, it might help you a lot ! Colliedr matrix