i am using a raycast to move a nave mash agent on a terrain but it will not register the hit on the terrain but it will register hits of objects on the terrain, the terrain has a box collider around it, and it also give the collider.tag as terrain but always sets the position to the Bottom left corner of the terrain no matter where i click any ideas?
this is the method :
void castRay()
{
Debug.Log("draw");
Ray ray = camera.ScreenPointToRay(new Vector3(Input.mousePosition.x, Input.mousePosition.y));
RaycastHit hit = new RaycastHit();
Debug.DrawRay(ray.origin, ray.direction * 10, Color.red);
if (Physics.Raycast(ray, out hit, 10000))
{
Debug.Log(hit.collider.name);
float x = hit.transform.position.x;
float z = hit.transform.position.z;
Vector3 hitPosition = new Vector3(x, 0.61f, z);
Debug.Log(hitPosition);
selectedUnit.GetComponent<NavMeshAgent>().SetDestination(hitPosition);
}
}
}