Hello,
I was looking for this problem in other threads but yould not identify anything similar.
What I want to do is the following: On pressing button “p” a plane shall appear on the surface of my terrain. I can choose in advance the x and z value; the y value shall be estimated with a raycast.
The code for the raycast is standard:
//---------------------------------------------------------------------
// start and end of an orthographic ray that hits the terrain and tells us the elevation
private static float rayTestTerrain(float xPos, float zPos, RaycastHit rayYPosHit)
{
Vector3 startRayPoint = new Vector3( xPos, 1000f, zPos );
Ray orthoTestRay = new Ray( startRayPoint, Vector3.down );
//Debug.DrawLine( startRayPoint, endRayPoint, Color.red, 10, false );
RaycastHit lala = new RaycastHit();
// actual ray test
Physics.Raycast( orthoTestRay, out lala, Mathf.Infinity, U3D_ModelManager.m_TerrainLayerMask );
return lala.point.y;
}
The result, though, is always 0:
(139.9, 0.0, 171.6)
UnityEngine.Debug:Log(Object)
Do you have any hints for me where to trace the error? The surface is a terrain, but I also created a simple plain on top to see if it gets a hit there, but negative…
Cheers!