- Home /
RTS style terrain changer.
Hello, Im making an RTS and theres a key problem, the buildings can go through the ground, I need to A) be able to flatten the terrain to suit the building B) cancel the placement of the object.
Answer by duck · May 03, 2010 at 08:46 AM
To flatten the terrain under the buildings at runtime, you'll need to use the undocumented terrain commands SetHeights and GetHeights. You can find more detailed information about how to use them here:
Modifying terrain height under a gameobject at runtime
If you need to make the action un-doable (within your game, not the editor), you'll need to first use GetHeights to sample the height date under the building area, and store the resulting height data in a temporary variable before flattening the ground. Then if the user wants to cancel/un-do the building placement, you can Destroy the building object, and re-set the terrain to how it was before by using SetHeights with the original stored height data.
SetHeights and GetHeights aren't undocumented; using them shouldn't cause any future problems.
oh, whoops I wondered why I hadn't added the undoc disclaimer on my linked answer! I was checking on the Terrain class docs to see if they were documented ins$$anonymous$$d of the TerrainData class.
Answer by Simon Wittber · Feb 08, 2012 at 04:27 AM
Terrain Destruction allows you to deform terrain using a heightmap texture. If you use a flat texture, you can carve flat surfaces into the terrain.