Hi! So what I want is to spawn a mesh in a random location in my terrain. But sometimes it spawns inside it and ejects in the skies like crazy! So I thought that if there was a way to make it spawn a little higher than the surface of the terrain whould solve the problem. So I’m stuck! I know that raycast could be useful, but I don’t understand how they work… So please help me!!!
For a Unity Terrain, you can use Terrain.SampleHeight. Take a look at the sample script:
Note that if the pivot of your object is not at the bottom of your object, you will need to add a constant amount to the ‘y’ to put your object on top of the terrain.