# Distribute terrain in zones

Hi, I have a terrain made up with mountains and flatland. Now I’ve come to the part where the player should be able to build in the flat areas but not on the mountain. The solution I thought of was to divide the terrain into zones. The flatland could be “zone 1” or just “flatland zone” and the mountains could be “zone 2” or “mountain zone”. Which way would be the easiest to do this?

Thank you!

You could have a Box Collider Trigger around the ‘Mountain’ terrain and when you enter the trigger you can’t build, but when you exit you can build again. This probably wouldn’t be the best for extremely large terrains though(exceeding 10 x 10 km or 100sq km)

Depending on how “mountainy” your mountains are and how “flat” your flat land is, you could always just do a hit.normal angle check. If the angle is above x, the player cant build

If your regions are of geometrical shapes like cylinder, cube, sphere, circle or rectangle it would be quite easy. You’d need to use points in the inspector and a class that will be able to check if something is in the region:
public class Region : MonoBehavior
{
public ArrayList pointsArray;

``````  public bool IsInArea(Vector3 v)
{
//Do mathematic calculation on v and the position on the points, returning whatever v is in the area or not.
}
//all of this is untested and theoretical code
}
``````

The mathematical calculation is:
Box/Cube/Rectangle/Square - Get 2 points, at the opposite sides of the shape. Check if v’s x,y,z values are between the values of the points.
Sphere - Get 1 point and a radius, and check the Vector3.Distance() between v and the point. If the distance is smaller than the radius, it’s in the sphere.
Circle - Like sphere, but with Vector2s and only the x and z axes.

Other solution, that is probably easier:
Add a collider component to your terrain, and make it trigger. the collider should be the shape you want your region. If you want irregular shaped region, make it a mesh collider with a mesh the shape of your zone (probably not practical to you). In a script attached to the object you can then write a method named OnTriggerEnter(Collider other) and in it write code to do when an object enters the region.

I hope at least one of the solutions help.
Good luck.