How to test collision with terrain

I have an airplane which is just a simple GameObject with a script attached to it that translates and rotates it. I would like to test it for collision against Terrain.

The Terrain has Is Trigger set to false and Create Tree Collisions to true. I have tried with OnCollisionEnter and OnTriggerEnter in a script on airplane but nothing happens. The airplane just passes trough.

Does it have a Collider and a Rigidbody attached?
Also you should move it using the Rigidbodys methods. Transform.Translate is not the right way if you want physics interaction.

The airplane has a box collider but not rigidbody because I want to move it with transform position and rotation.

I have tried putting also a rigidbody with isKinematic to true.

This is my function:

	void OnCollisionEnter(Collision collision)
	{
		Debug.Log(collision.gameObject.name);

		if(collision.gameObject.name == "Terrain")
		{
			Instantiate(explosion, transform.position, transform.rotation);
			
			Destroy(gameObject);
		}
	}

When airplane hits the terrain the Debug.Log() logs “Terrain” but it wont enter the “if” statement. Why is that ?

You should use the equals method to compare strings.

if(collision.gameObject.name.Equals("Terrain"))

I have tried that and now when I put Is Kinematic on Rigidbody to false it works ok. The airplane explodes. But now its behaving really funny because I use Transform to translate and rotate. So Is Kinematic needs to be set to true but that way again the “if” wont pass.

I have found the solution. On airplane the Rigidbody has to be set Is Kinematic to true and the Box Collider value Is Trigger also needs to be set to true.

This is shown in Box Collider Help in Collision Action Matrix.