- Home /
Raycast not hitting terrain.
So I have a terrain with a terrain collider attached and is trigger is deactivated. When I place an object just above it and try to raycast downwards ( checked if ray is penetrating by drawing the ray) it won't register the hit. I am using 4.5.1f3 free version and have no options to try. Any suggestions ?
your going to need to post more info buddy; why don't you post the code that isn't working right?
Sure, the only code I have is:
void movementUnit(){
//Get point
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
this.q = ray;
RaycastHit[] hits = Physics.RaycastAll (ray.origin, ray.direction, 1000);
Debug.Log (hits.Length + " " + ray.origin + " " + ray.direction);
foreach (RaycastHit hit in hits) {
Debug.Log(hit.transform.tag);
if(hit.transform.tag == "Ground"){
processInput(this.transform.position,hit.point);
break;
}
}
}
void Update(){
if(Input.Get$$anonymous$$ouseButtonUp(0) && dfInput$$anonymous$$anager.ControlUnder$$anonymous$$ouse == null){
movementUnit();
}
}
void FixedUpdate(){
Debug.DrawLine(this.q.origin,this.q.direction*1000,Color.yellow);
}
I am using Arong Granberg path finding and if I create a new empty box and place it under "ground" layer I can hit it with a raycast as well as other object in different layers. The only object I can not hit is the mesh I have for terrain. In addition if I create a new terrain and add same layer/tag specs to it I am able to hit it too. It is very weird to be hones. Anything else I can post that would help ?
Answer by s.23 · Jul 01, 2014 at 08:30 AM
Figured it out, something to do with a processing script and the prefab it creates. It is still weird that you can have a terrain object that is not hittable with a raycast, thanks for help.
$$anonymous$$aybe you can replace your
something to do with a processing script and the prefab it creates
with the actual solution you used to solve your problem. It will help everyone referring to this question in future. :-)
Your answer