Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

randomly generated "territories"

Discussion in 'General Discussion' started by jg2115, Apr 26, 2014.

  1. jg2115

    jg2115

    Joined:
    Jun 25, 2013
    Posts:
    19
    Hello, I am starting on a new project where there will be different territories to capture and control, like risk. I am trying to make them randomly generated, and I don't know how to go about that. No terrain or anything, just flat territories in the style of risk. Also, I would want to change their colors later on so I can't just have lines. Any suggestions?
     
  2. smd863

    smd863

    Joined:
    Jan 26, 2014
    Posts:
    292
    $randomTerritories.jpg

    Here's a quick version of how I would approach it.

    1) Random dots
    2) Connect random dots into triangles. Maybe simply select a random location on the map, and if it is not already inside a triangle, connect the nearest three dots that will create a valid triangle.
    3) Assign each territory to a single triangle. Randomly expand each region into adjacent triangles until all triangles are occupied.
    4) Discard interior lines. Apply recursive line subdivision to territory outlines to create a more natural appearance. For each line in the outline, split it into two lines at the midpoint, and shift the midpoint randomly perpendicular to the line. Repeat until lines are sub-pixel length.

    Those are only general steps, and there are other considerations in making an interesting map. You may want to alter it to create continents with limited connectivity (and continental bonuses). Larger territories generate more armies but have more fronts to defend.
     
  3. jg2115

    jg2115

    Joined:
    Jun 25, 2013
    Posts:
    19
    Thank you for the suggestion, but a few questions. Are you suggesting for the lines I use pictures, or a 3d line? Also how would you get the midpoint and bend the line? Also how would you even draw it(not looking for any code just suggestions)?
     
    Last edited: Apr 26, 2014
  4. jg2115

    jg2115

    Joined:
    Jun 25, 2013
    Posts:
    19
    Alright i figured out actually MAKING the territories by procedurally generating meshes, but now for as far as picking the location/outline of the territories. Once I generate random points, I'm not sure of the best way to form the points into shapes without overlapping. Any suggestions?
     
  5. minionnz

    minionnz

    Joined:
    Jan 29, 2013
    Posts:
    391
  6. jaybennett

    jaybennett

    Joined:
    Jul 10, 2012
    Posts:
    165
    Yes I thought about using a Voronoi diagram to achieve a similar result. The math and code is pretty intimidating though... especially if you've never generated more than a quad before.
     
  7. minionnz

    minionnz

    Joined:
    Jan 29, 2013
    Posts:
    391