Question by
DwarfinChief · Oct 25, 2018 at 05:56 PM ·
terrainterraindata
Problems with terrain GetSteepness
Hi Guys,
I'm needing to calculate the current steepness under my first person controller.
In Update() I'm getting all the current values and later spitting them out to a screen label for reference.
The problem - GetSteepness() is always returning a number between 23 and 26. 23 on total flat areas and 26 on very steep hillsides. I don't think this is correct? Can someone check my code? It's the "currentSteepness" value that I believe needs fixed.
void Update () {
AdjustedLocation = FirstPersonController.transform.position - terrain.transform.position;
Vector3 DividedBySize = new Vector3(AdjustedLocation.x / terrain.terrainData.size.x,
AdjustedLocation.y / terrain.terrainData.size.y, AdjustedLocation.z / terrain.terrainData.size.z);
Vector3 MultipliedByHeightmapResolution = DividedBySize * terrain.terrainData.heightmapWidth;
capturedX = (int)Mathf.Floor(MultipliedByHeightmapResolution.x);
capturedZ = (int)Mathf.Floor(MultipliedByHeightmapResolution.z);
currentSteepness = terrain.terrainData.GetSteepness(capturedX / terrain.terrainData.size.x, capturedZ / terrain.terrainData.size.z);
currentHeight = terrain.terrainData.GetHeight(capturedX, capturedZ);
}
A screenshot of my terrain values:
capture.png
(6.7 kB)
Comment