Found this code online.It gives the impression that a flat terrain is tilted by setting the height at one end higher.Anyone know what to change to allow for that tilt to be given a value right now its tilting at around a 60 degree angle and Iwant to be able to set it for whatever value I need instead. The relevant code is contained from line 34-79 I tried imputing value in most of those lines but didn't get the desired effect so asking here.Thx Code (CSharp): using UnityEditor; using UnityEngine; using System.Collections; using System; using System.Collections.Generic; public class terraintilt : EditorWindow { static float _startingX = 0f; static float _startingY = 0f; static float _endingX = 1f; static float _endingY = 0f; static float _scale = 0f; [MenuItem("Meriwether/Show Terrain Slope Tool")] static void ShowWindow() { EditorWindow.GetWindow<terraintilt> (); } public void OnGUI(){ if (GUILayout.Button("Apply Slope")){ SlopeTerrain(); } if (GUILayout.Button("Lower Terrain")){ LowerTerrain(); } if (GUILayout.Button("Scale Terrain")){ ScaleTerrain(); } } static void SlopeTerrain(){ GameObject source = Selection.activeGameObject; if (source == null || source.GetComponent(typeof(Terrain)) == null){ Debug.LogError("Cannot apply slope, no valid terrain selected!"); return; } Terrain sourceTerrain = (Terrain)source.GetComponent(typeof(Terrain)); TerrainData tdata = sourceTerrain.terrainData; float[,] sourceHeights = tdata.GetHeights(0,0,tdata.heightmapResolution,tdata.heightmapResolution); float[,] newHeights = tdata.GetHeights(0,0,tdata.heightmapResolution,tdata.heightmapResolution); bool clippedBelow = false; bool clippedAbove = false; for (int i = 0; i < tdata.heightmapResolution; i++){ for (int j = 0; j < tdata.heightmapResolution; j++){ float floati = i; float floatj = j; float widthp = floati / tdata.heightmapResolution; float heightp = floatj / tdata.heightmapResolution; newHeights[i,j] = sourceHeights[i,j] + Mathf.Lerp(_startingX, _endingX, widthp) + Mathf.Lerp(_startingY, _endingY, heightp); if (newHeights[i,j] < 0){ clippedBelow = true; } else if (newHeights[i,j] > 1) { clippedAbove = true; } } } if (clippedBelow){ Debug.LogWarning("Warning: Clipped below 0!"); } if (clippedAbove){ Debug.LogWarning("Warning: Clipped above 1!"); } tdata.SetHeights(0, 0, newHeights); tdata.RefreshPrototypes(); sourceTerrain.Flush(); } static void LowerTerrain(){ GameObject source = Selection.activeGameObject; if (source == null || source.GetComponent(typeof(Terrain)) == null){ Debug.LogError("Cannot lower terrain, no valid terrain selected!"); return; } Terrain sourceTerrain = (Terrain)source.GetComponent(typeof(Terrain)); TerrainData tdata = sourceTerrain.terrainData; float[,] sourceHeights = tdata.GetHeights(0,0,tdata.heightmapResolution,tdata.heightmapResolution); float[,] newHeights = tdata.GetHeights(0,0,tdata.heightmapResolution,tdata.heightmapResolution); float lowestValue = 1; for (int i = 0; i < tdata.heightmapResolution; i++){ for (int j = 0; j < tdata.heightmapResolution; j++){ if (sourceHeights[i,j] < lowestValue){ lowestValue = sourceHeights[i,j]; } } } for (int i = 0; i < tdata.heightmapResolution; i++){ for (int j = 0; j < tdata.heightmapResolution; j++){ if (sourceHeights[i,j] < lowestValue){ lowestValue = sourceHeights[i,j]; } newHeights[i,j] = sourceHeights[i,j] - lowestValue; } } tdata.SetHeights(0, 0, newHeights); tdata.RefreshPrototypes(); sourceTerrain.Flush(); } static void ScaleTerrain(){ GameObject source = Selection.activeGameObject; if (source == null || source.GetComponent(typeof(Terrain)) == null){ Debug.LogError("Cannot lower terrain, no valid terrain selected!"); return; } Terrain sourceTerrain = (Terrain)source.GetComponent(typeof(Terrain)); TerrainData tdata = sourceTerrain.terrainData; float[,] sourceHeights = tdata.GetHeights(0,0,tdata.heightmapResolution,tdata.heightmapResolution); float[,] newHeights = tdata.GetHeights(0,0,tdata.heightmapResolution,tdata.heightmapResolution); for (int i = 0; i < tdata.heightmapResolution; i++){ for (int j = 0; j < tdata.heightmapResolution; j++){ newHeights[i,j] = sourceHeights[i,j] * _scale; } } tdata.SetHeights(0, 0, newHeights); tdata.RefreshPrototypes(); sourceTerrain.Flush(); } }
in line 58 it calculates new height, so adjusting the starting and ending values should do it. but note that it looks like to be normalized value, since it clips them between 0-1 in the next line. in that case,check your terrain settings - it has that "terrain height" value, so getting value 1 from that line 58, would equal that max height value.
Ok nice thx worked it out the key is to change the line 11 static float _endingX = 1f; to whatever smaller float value u prefer.