Problems destroying object on collision with Terrain

I need to destroy an object when it collides with my terrain. From what I’ve read in other posts I need to use OnCollisionEnter, not OnTriggerEnter and object cannot have ‘is trigger’ checked (and there is my problem) the object that needs to be destroyed ‘has’ to have a trigger as a number of other game mechanics depend on it.

How do I get around this problem

???

Don`t worry u can use OnTriggerEnter aswell but the ground or the object you want to destroy needs an attached rigidbody otherwise it will not work.

Use OnTriggerEnter with isTrigger on the Collider. It will work (just tested that myself)

Ok its fair to say this problem still perplexes me, even though its now resolved.

There are many conflicting answers to this issue, most of which say Terrain Colliders are not triggers or this/that is no longer valid in Unity 5.

I stripped away all the crap from my project and basically put in the bare essentials on another new build. Created the most basic script and tried again.

using UnityEngine;
using System.Collections;

public class DetectCollision : MonoBehaviour
{

	public GameObject playerExplosion;


	void OnTriggerEnter (Collider other) 
	{
		Debug.Log ("Collision Detected");

		if (other.tag == "Player")
		{
			Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
			Destroy(other.gameObject);
		}
	}
}

I made no adjustments to my Terrain collider, simply added this script to the terrain. My player object has a rigidbody attached, a mesh collider, kinematic is unchecked and collision detection is set to discrete.

Everything works fine now. Thought I may have some issues as the player object moves quite quickly, but nothing, its all good (at least for now)

The only issue I did have was that Unity 5 has some weird bug where sometimes the terrain collider is not in alignment with the terrain (so you either explode prematurely or move though the terrain) I believe the UT guys are looking into this so I’m guessing it will be patched soon. As a quick fix just save your project and restart unity, that seems to fix it.

Anyway, hopefully this will help any noobs (myself included there) in case they are having similar issues.

:slight_smile: