• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Generating randomized clusters of objects around a map

Stamos22

Member
Hello,

I'm currently working on a hunting game and trying to randomly generate clusters of trees. The trees are objects (and need to be since the player can interact with them).

I have managed to randomly scatter trees all over the map, and this is fine for some maps, but I would really like to figure out a way to create clumps, instead of scattering them everywhere.

My guess would be to have a few container objects that get scattered around the room, and then those containers spawn the clusters of objects. I'm not sure how to randomly scatter the trees from those containers. For example, if I wanted to scatter a group of 3-15 trees in a certain radius without them overlapping.

Any help would be appreciated!
 

kburkhart84

Firehammer Games
I think you are on the right track. Assuming this is happening at the beginning and isn't happening during gameplay, I'd do the following.

1. Scatter a few objects in random places. Each one, check the previous ones and make sure they are enough distance from each other.
2. Scatter the trees in random distances and directions from the 1st objects. Each one, check physical distance to each tree prevously created, and re-create it if it is too close.

That process is actually common enough, checking if it is too close and redoing it.
 

Stamos22

Member
Ok that makes sense, thanks for clearing that up. As a follow up question, would there be a way to make a snaking/winding river from objects? Each river tile is also an object and in a perfect world I would have a river or two cutting across my map at random. For this is it possible to sort of lay one object at a time in a line with some left and right variation to simulate the river winding? This seems like a much more complicated problem than the tree clusters.

Again, thanks for the help it's much appreciated!
 

kburkhart84

Firehammer Games
With a river, I would do something like simulate something moving from one side to the other.

1. Start on the left, pick a random position, and pick a random direction to move. Since you are moving right, pick an angle between maybe -45 and 45. Also pick a random amount of steps before the next big direction change.
2. Drop a "river piece" at your location.
3. Move a "step" in the direction you chose. Check randomly if you want to continue straight or add an ever so slight deviation(maybe 10 or 15 degrees) to the direction.
4. Repeat 2 and 3 until you have done enough steps for the big direction change.
5. Start back at #1 again, and repeat this process until you get to the right side.

You would have to tweak all these parameters until it looks good. You could also do some forced values for example if the angle is too steep(or allow it so the river is more varied).
 

Stamos22

Member
That's so smart! Thanks so much for your help. I feel like I've gotten to a point where I understand a lot of basics but it's this sort of thinking that I need to work on. I guess it's why I got a 50 in math and became an English teacher haha.

Thanks again, this is very helpful!
 
Top