How to create ideal spawn points on Random Generated Maps?

I am creating a turn based game which uses a map generator I made that uses Perlin Noises. I still didn’t put unique features on each map style, but I think it’s getting neat:
(Green/Red Cylinder is the Playing Area)
Earth:


Hot Mountains Planet:

Asteroid Field:

Acid World:

Here is a problem though: How do I make the game choose a spawn point for each player on the area? I mean, I know I can make the game save points where solid terrain were generated and choose them randomly as spawn points, but what if the playing area has mostly water or empty space? A solution I thought could work was to check how much terrain is generated on random places but It would be too expensive for the server to do this.

  • Create a recursive RayCast function casting a Ray downwards from a random location on the X and Z axis and from world height on the Y axis
  • Read the result of the RayCast and determine if that would be a valid place to spawn
  • If it’s invalid (water, etc) run the function again
  • Do this for as many spawn points as you want

I have no idea if this is a good way of doing it but that’s what I thought of

It’s what I thought but also checking if there is enough solid terrain around the location, but it would take too much time to do so or lag, so I think it wouldn’t be the best option.

It wouldn’t take a long time to do or create lag, it’s only done once at the beginning of a round I thought.

Why are you saying it would create lag?

Doing a couple hundred RayCasts at the beginning of a round won’t cause lag. Your perlin noise generator would be more expensive than that.

Its a 500500 loop to generate all of it. If I check each place for the positions it will take long. An AI for a game I had checked a grid map of 1515 and it already seemed to lag, so I can imagine the effect it should give here.

But I do think I have found a solution. Save positions where the generated terrain height is high enough on a table. Then I iterate only on these positions and check the one that has more of it on their areas. This becomes the place where they will spawn.

1 Like

But you don’t have to do the checking for every single location only until you find one that you want to use to spawn.

You can always try it and look at the results using the performance tab.

Remember this is running once at the beginning of a round, not every frame or step.

Yeah but its so much distance the players should start away from each other that it will loop a lot still. I think I should have made the map chunk based so I could get the chunk with the hugest amount of available spaces.

Okay, I finally figured an idea that will fix this issue:

I can check using the randomseed for some points in the center of the map before it generates, and if most of them are water I use a height compensator to instead generate the entire map higher, and the same if it’s too high, so I can still have some lakes and rivers.

From what I tested the following solution can be made:

When you generate terrain with perlin noise you get a value which you use to generate the terrain height, which varies on x and z coordinates. What I did was check the average height value generated on the playing area, which we can call averageH.

On my generator at least, the best outcome of ground/water proportions happens when the averageH is .6, so we will create a compensation value x = averageH-.6.

Now we can start the world generation, and every time a height value is generated we substract it by x. Example: noiseHeight-=x

This will make so the game always try to generate the map at the desired location closer to the height you want. In my case I wanted it to get closer to a height where it has some islands , which seems to work just fine. (tested about 30 times, and not even once spawned only water).

2 Likes