- Home /
Terrain Tag OnControllerColliderHit not showing
Greetings Answers,
I am trying to run a script on my character that detects collision when my char controller hits a terrain tree mesh. I have attached my project, I've written a simple test script (below) and attached it to my character.
function OnControllerColliderHit(hit:ControllerColliderHit){
if(hit.gameObject.tag == "terrain"){
//do nothing
} else {
Debug.Log(hit.gameObject.tag);
}
}
function OnTriggerEnter (other:Collider)
{
Debug.Log("triggered");
}
The triggered or OnControllerColliderHit function are both detected if I just drag their respect prefabs to the scene view. However, the script does not work using either method if I draw the tree using the terrain tool. However, the script does recognize the terrain, which is why I have it commented out. The trees and terrain have been tagged differently. From what I understand tagging and then detecting the collision is the only way to gain access to a gameObject built with the terrain tool. I essentially am trying incorporate tree cutting into my game, I will eventually want to detect collision between an axe or pick and a terrain object like a tree or rock, but this is a good starting point for proof of concept with a terrain mesh. Simplest functionality would be to destroy the terrain game object after a period of time.
Unity Project: terrain collide test
Screen Shot: pic
I've tried many of the suggested techniques and believe I am doing everything correctly. The middle tree is the one with the problem.