Creating discrete-leveled terrain.
I have a height map array that I use to set terrain heights . This way provided values serve as heights for points which correspond to grid lines intersections; heights in between are produced by (linear?) interpolation.
But what I would like to get is a terrain, in which height map array sets heights for grid cells, rather than grid lines intersections. Like this: Is there a way to obtain such behavior?
Answer by DawdleDev · Apr 30, 2018 at 01:59 PM
Don't use a terrain. You're thinking about the wrong usage for a terrain. What you could do is this (in pseudocode):
2DListOfFloats heights;
public GameObject cubePrefab;
OnEnable () {
for(int y = 0; y<heights.collumncount;y++) {
for(int x=0;x<heights.rowcount;x++) {
GameObject cube = Instantiate (cubePrefab, new Vector3 (x, y, heights[y][x]), Quaternion.identity, WorldContainer) as GameObject;
cube.transform.localScale = new Vector3 (1, 1, heights[y][x] * 2);
}
}
}
cubePrefab needs to be assigned in the editor. It needs to be a basic cube (with whatever texture you desire). Heights also needs to be assigned, but that can be procedural or random. Try perlin noise.
Hope this helps!
Your answer
Follow this Question
Related Questions
How to generate endless 2d terrain 0 Answers
Proceduraly generated rivers 0 Answers
Weird vertices appear when generating grid full of quads 0 Answers