How do you reference a terrain to detect collisions?
I am trying to detect it with raycast like
if(hit.collider == Terrain)
but it will never detect. I know of controller.isgrounded, but I need raycast. Thanks
How do you reference a terrain to detect collisions?
I am trying to detect it with raycast like
if(hit.collider == Terrain)
but it will never detect. I know of controller.isgrounded, but I need raycast. Thanks
Tag your terrain as Ground, then check if(hit.gameObject.CompareTag("Ground"))
Making tags is a little funny – select anything and Tag->AddTag, open the Tag foldOut and enter the new name. Or Edit->ProjectSettings->Tags. Then select the Terrain and Tag->Ground.
Another way is to put the ground on a layer named Ground (have to make it) and rayCast only against that layer. The ray will go straight through everything except the ground, so you can just use if(Physics.Raycast(....))
old thread, but i still found it useful… btw, in unity 4.5 c# i needed to change this slightly to the below
if(hit.collider.gameObject.CompareTag ("Ground"))
{
//do your thing
}
Thank you for your help it works now
– superventure