Hello,
I am creating a dynamic terrain and would like to know the x and z position if I clicked on the terrain or on a game object. I am using a raycast for this:
[code=CSharp] RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Debug.DrawRay(ray.origin, ray.direction * 5000, Color.red, 1000000f); if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { if (hit.transform.gameObject != null) { Debug.Log("HIT " + hit.transform.gameObject.layer + ":" + hit.point.x + ", " + hit.point.y + ", " + hit.point.z + ", " + getRealHeight(hit.point.x, hit.point.z)); } } [/code]In the two screenshots below you can see the point where I clicked from two perspectives and the last three lines in the log correspond to the Debug.Log line in the code above. Although in this example the x position seems correct, the y position is incorrect (see position of the tank object in the second screen). The DrawLine shows that it should have given the correct values. Sometimes the values are correct, but other times the x and/or y position is incorrect. I have tried to add the terrain to a seperate layer (25), but still I get incorrect values. ![alt text][1] ![alt text][2] [1]: /storage/temp/66280-unity-raycast.jpg [2]: /storage/temp/66281-unity-raycast-1.jpg