- Home /
raycast from a point straight down
I would like to instantiate a character from a random point, on a terrain. the only problem is that i won't know how high my terrain will be at that spot. my thought was i could ray cast from a point above the terrain so that I could take the raycasthit.point, and create the player.
the problem is i can't figure out how to ray cast without a camera (It may not even be possible)
so If someone could tell me how or link me to some documentation that would be great.
And if there's some other/better way to do this, I would definently try it.
thanks
Answer by robertbu · Oct 04, 2014 at 09:05 PM
First, you can use Terrain.GetHeight() instead of ray casting. If you really wanted to do a Raycast, it could be something like this:
var hit : RaycastHit;
var ray = new Ray(somePosition, Vector3.down);
if (Terrain.activeTerrain.collider.Raycast(ray, hit, 1000)) {
Debug.Log("Hit at "+hit.point);
}
Ah, Thanks, i was looking for something like GetHeight, thanks for the help
Hi Roberbu, could you please translate this into C#? This could help me out, but ye... Am not using Javascript...