- Home /
Paint terrain between 2 or more Vector3?
hey! I am actually pretty new to Terrain modification so please excuse this question if it might be stupid.
So what i wanna do is, i have an array of Vector3s. like this: and now i simply wanna paint a line on the terrain from Element 0 to element 1 to element 2 ..to 3... and so on.
if you are interested what i need this for. i wanna paint roads on a dynamic generated terrain. which looks like this:
the green line is the A* debug path which goes from village to village. and all i wanna do now is painting it
so. i will just answer myself - or not answer, rather than a status update. what i got so far is this:
using UnityEngine;
using System.Collections;
public class PaintRoad : $$anonymous$$onoBehaviour {
float[,,] element;
int mapX, mapY;
TerrainData terrainData;
Vector3 terrainPosition;
public Terrain myTerrain;
float[,,] map;
private Vector3 lastPos;
void Awake()
{
map = new float[myTerrain.terrainData.alphamapWidth, myTerrain.terrainData.alphamapHeight, myTerrain.terrainData.alphamapLayers];
element = new float[10, 10, myTerrain.terrainData.alphamapLayers];
terrainData = myTerrain.terrainData;
terrainPosition = myTerrain.transform.position;
lastPos = transform.position;
}
void Update()
{
Update$$anonymous$$apOnTheTarget();
}
void Update$$anonymous$$apOnTheTarget()
{
//just update if you move
if(Vector3.Distance(transform.position, lastPos) > 1)
{
print("paint");
//convert world coords to terrain coords
mapX = (int)(((transform.position.x - terrainPosition.x) / terrainData.size.x) * terrainData.alphamapWidth);
mapY = (int)(((transform.position.z - terrainPosition.z) / terrainData.size.z) * terrainData.alphamapHeight);
map[mapY, mapX, 0] = element[0, 0, 0] = 0;
map[mapY, mapX, 1] = element[0, 0, 1] = 1;
myTerrain.terrainData.SetAlphamaps(mapX, mapY, element);
lastPos = transform.position;
}
}
}
put this on a cube that is on/over your terrain and move this cube. this will paint something black on the terrain where the cube is. now i only need to find a way to paint from a list of Vectors?
Your answer
![](https://koobas.hobune.stream/wayback/20220612100506im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Change GUILayout.Button font color 3 Answers
Fatal Error in gc : GetThreadContext Failed 0 Answers
Making a mesh transparent 1 Answer
How do I implement a fill mechanism in a drawing game 0 Answers
Can't paint grass on raised terrain 0 Answers