Collision detection between target and sphere not working (3d),Collision between target and sphere not working (3D)
So I've gone through all the similar questions in the forums, 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? Appreciate all insight :)
According to your script and what you have done in editor, your "OnTriggerEnter" method should work. Please check your script is attached to which gameObject. it should be attached to one of your gameObject, either sphere or box.
Your answer
Follow this Question
Related Questions
Get list of enemies in range 1 Answer
OnTriggerEnter2D not working 1 Answer
Collision issue, Plz help 1 Answer
Trouble Respawning objects after colliding with trigger 0 Answers
How do I detect a collision between two objects using Bolt? 1 Answer