- Home /
Why doesn't my prefab collide with my map?
So I made this very simple map and I'm trying to make it so whenever the bullet hits one of the environment objects, the bullet destroys itself. So I made this short code:
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Terrain"))
{
Debug.Log("Bullet hit terrain");
Destroy(gameObject);
}
}
The bullet prefab has a Sphere Collider with trigger on and Rigidbody with no gravity. The terrain objects have Box Collider with trigger off and Rigidbody with no gravity and is kinematic on. I don't know why the bullet is not interacting with the terrain.
Answer by Captain_Pineapple · Jul 14, 2020 at 08:16 AM
You basically answered your question yourself: Sphere Collider with Trigger on.
I strongly suggest you read this here: docs.unity3d.com/Manual/CollidersOverview OnCollisionEnter does not trigger with a Trigger and a Collider. Your current situation needs OnTriggerEnter instead.
Ah! That worked! I don't know how I forgot to try Trigger. Thank you!
Your answer
Follow this Question
Related Questions
How to make arrow stick to environment ? 3 Answers
Best collision detection method? 2 Answers
OnCollisionEnter isnt called when player lands on object 1 Answer
Why there is no Collider.IsTouching(...) ? 2 Answers
Physic based golf game - ball bouncing off the connection of colliders on flat surface 2 Answers