- Home /
How to test for a collision with a Terrain
I have an airplane with Rigidbody and a Collider attached to it. The Rigidbody has Is Kinematic set to true because I use Transform to change its position and rotation. I would like to test for a collision if airplane hits ground.
This is my code that's a component of airplane:
void OnCollisionEnter(Collision collision)
{
Debug.Log(collision.gameObject.name);
if(collision.gameObject.name == "Terrain")
{
Instantiate(explosion, transform.position, transform.rotation);
Destroy(gameObject);
}
}
The Terrain (ground) has Is Trigger set to false and is set as Static. When I test my code Debug.Log() logs "Terrain" but the "if" statement wont pass. If I try to collide with other GameObjects (instead of "Terrain" some other name) that have a Rigidbody and a Collider everything works ok and "if" statement passes.
Answer by tibor698 · Nov 13, 2013 at 06:05 PM
I have found the solution. Box Collider value Is Trigger has to be set to true and the function has to be changed to OnTriggerEnter().
This is shown in Box Collider Help in Collision Action Matrix.
Your answer
Follow this Question
Related Questions
Modifying height directly on a Rigidbody Object without gravity 1 Answer
how to create Magnetic repulsion ? 0 Answers
Physics AddForce reduced when 3 objects are colliding 1 Answer
Handling colliders on hundreds of asteroids (not procedural asteroids) ...URGENT 3 Answers
Hooking RigidBody.AddForce 0 Answers