- Home /
Edit Terrain via scripting
Is it possible to lower the terrain without going in to the terrain editor and using the brush? I want to lower it where there is a mesh. I know it is possible - I'm just not sure where to start! Any advice is appreciated.
I saw a youtube video of a $$anonymous$$ing game where they did it (so at least its possible). Theres something tricky about it though because terrains are a height map.
Just curious, is this an editor script or a runtime thing?
Here I found that video I was thinking of
This is an editor script. Ever used EasyRoads from the Asset Store? There is a free version online. That allows you to change terrain at a mesh (I think).
Yea easyroads is fun, it lays out a benzer curve road mesh and flattens any terrain beneath it. $$anonymous$$y brother and I have a pretty crazy racecourse. There's an easy rivers too.
Have you tried decifering the scripts from those, and copy-pasted from them? I bet you have already :-)
Answer by ckfinite · Jun 05, 2011 at 11:16 PM
Terrain is made using a heightmap, and you can alter it through this: http://unity3d.com/support/documentation/ScriptReference/TerrainData.html
Okay, it sometimes just seems like some people don't know how on here. Anyway, what I would do is I would find the Vector3 distance from the terrain's origin to the affector mesh, then map that into terrain heightmap space by dividing the distance by heightmapScale. Then I would round the x and z to an int, and that should be your affected heightmap coordinate. I would recommend then using something like SmoothStep to apply that smoothly to the surrounding coords.
This is a untested by me technique, so the details might be wrong, but the overall system should work.
will the changes done by script change the terrain for ever or till the end of the current game?
I haven't tested it, but according to the docs, any game time changes to terrain data will be permanent.
Your answer
