We will implement a function to evaluate a location given its height and surrounding points:
- Declare the function for evaluating the quality:
public static float GetHeightQuality (Vector3 location, Vector3[] surroundings)
{ // next steps }
- Initialize the variables for handling the computation:
float maxQuality = 1f; float minQuality = -1f; float minHeight = Mathf.Infinity; float maxHeight = Mathf.NegativeInfinity; float height = location.y;
- Traverse the surroundings in order to find the maximum and minimum heights:
foreach (Vector3 s in surroundings) { if (s.y > maxHeight) maxHeight = s.y; if (s.y < minHeight) minHeight = s.y; }
- Compute the quality in the given range:
float quality = (height-minHeight) / (maxHeight ...