Selecting grid members with a minimum distance apart.

Hey all

I’m slowly learning how to make a civ-like map generator and I’ve run into a minor wall. I’m looking to select a few random hexes on my map to seed continents with in the generation process, but I’m not exactly sure how to make sure they have a minimum distance apart. I’m used to visual scripting in something like Rhino and Grasshopper, where to do this I would simply test the array of points with a “find nearest” and filter out the distance to the top few. For Unreal I’m not so used to using its array logic so I’m not sure where to begin.

I think I know I have to use a for-loop system which will take each generated object and test for distance but I can’t quite figure out how to do it with Unreal’s logic. Because if it’s a loop body I have nothing to compare the first one selected to. So I have no idea how to deal with that first selection. I also am worried that there’s potential here for an infinite loop error if it can never find something in the right area. This will be useful for me later on in the generation. So I need to use a loop with break which says “alright we’ve tried to fins something for 10 seconds, give up and tell the player.”

How should I go about this?

Huzzuh! That worked! TY!!

So you have an array of hexes.

Make a new empty array, which will hold the selected hexes.

Randomly select one hex and put it in the new array ( remove from hex array ).

Then do this N times ( the number of hexes you want ):

  • Randomly select one hex from the hex
    array and compare it’s distance to
    all those in new array.

    If it’s good, put it in the new
    array.

    Remove it from the hex array (
    whether it’s good or not ).