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

Question Locate points along perimeter of gridshape (island) in correct order

Discussion in 'Scripting' started by ArianB, Oct 23, 2020.

  1. ArianB

    ArianB

    Joined:
    Mar 12, 2018
    Posts:
    8
    Hey,

    I have a island I've procedurally generated using a grid, and I now need to find all the points along the perimeter (corners and edges), however they have to be in order, as in, one by one. Like shown below

    unityhelp.jpg

    The only solution i can think of is to have a bot in the update loop jumping from tile to tile along the perimeter until it comes back to itself, and adding each tile into a list.

    However, I'm wondering if there is a more efficient way to do this, maybe using for loops or something?
    If there's something i'm explaining poorly just let me know!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    If the rule is never-diagonal (ie, always north, south, east, west transitions), it's easy to write a bot that steps around it until it arrives at the beginning again, keeping a list of places it has been.

    I don't think the choice of loop construct would affect efficiency significantly.
     
  3. ArianB

    ArianB

    Joined:
    Mar 12, 2018
    Posts:
    8
    Thanks for your reply! Yes, the rule is never diagonal. I guess that's the way to go then
     
    Kurt-Dekker likes this.