- Home /
Answer by robertbu · Nov 24, 2014 at 10:24 PM
This question is a bit strange. How you will accomplish the task will depend 1) on the orientation of your geometry, and 2) on the nature of your geometry. If you are talking about and XZ coordinate in which you want the 'Y'. Then:
If your ground is a Terrain, you can use Terrain.SampleHeight().
If your ground is some other collider, then you use a Raycast(). If you only want to check a single collider that you want to use for the ground, use Collider.Raycast(). If you want to check any objects in the scene, use Physics.Raycast(). You will pick a 'y' height guaranteed to be above your ground and use Vector3.down for the direction.
http://docs.unity3d.com/ScriptReference/Terrain.SampleHeight.html
http://docs.unity3d.com/ScriptReference/Collider.Raycast.html
http://docs.unity3d.com/ScriptReference/Physics.Raycast.html
I did some testing and found out that Unity's navigation system can take Vector2's as is, but thanks for your answer.