
Hello, I have to use this Diagram to help explain my issue.
I am essentially Setting the Height of the Terrain underneath the Cube to the height of the Cube.
The Issue is, I cannot find a way to get the position of the Cube relative to the Resolution of the Terrain. ( If I use the actual position of the cube it simply says it is out of bounds ) Im sorry if this is hard to explain, but Im hoping people may have had done things similar to this before.
All help is appreciated. thankyou
Terrain has little “squares” that have the corners raised/lowered. SetHeight takes the corner #'s as input. Ex: setHeight(1,3)
goes one corner east and 3 north, and changes that one. Since the squares aren’t 1 meter x 1 meter, you have to convert world x,z into nearest corner #.
To convert, 1st get the width of each square: divide the total Terrain width by the number of squares. Then divide your world x,z by those and round to the nearest. Ex: if you are at x=22 and terrain tiles are 5 wide, you are closest to corner #4, at x=20.
Searching for “Unity Terrain Set Height” gives a result from Unity Answers where they do all that math (or try “Unity world Terrain” for another.)