- Home /
The question is answered, right answer was accepted
How do I get the y coordinate of a terrain at any time?
Hello guys!
I'm trying to make a hack'n'slash type game. I have some issues with my character's movement script. I would like to know if i can get the y coordinate (aka the height of the terrain) just under my character so he could stay "fixed" to the ground. Thank's in advance =)
Have a look at raycasts. Just cast down and you'll know the height difference between the terrain and the starting point of the raycast.
Answer by Dave-Carlile · Sep 15, 2015 at 05:28 PM
You can use the Terrain.SampleHeight function to get the terrain height at a given position. In fact, the sample code there is moving an object's y to the terrain height.
Thank you very much Dave! I've been able to move my character without him going into the ground =) Give that man a cookie someone! Thank's again!
Follow this Question
Related Questions
Having some serious issues making height maps work. 1 Answer
Editing Terrain Topology at Runtime 0 Answers
Terrain height raycasting? 1 Answer
How to code a burst of speed? 1 Answer
Get Height of Terrain in Script 1 Answer