Procedural Generation Placing Spawner

Been a while since I’ve posted on here, but since you’re talking procedural generation I thought I’d chime in. I’ve recently built a python version of the methods detailed here. At present it’s pretty much fully functional and game engine independent. Here’s the sort of things it can generate:

These are just some basic room/corridor set ups it can create (there’s loads more, it’s quite customisable, with a variety of utility functions). It also features it’s own grid based path finding as well so that it can AI can navigate procedurally generated terrain. It wouldn’t be hard to edit it for infinite level generation. And clever seeding of the random module would allow the player to return to the same point while keeping each level completely different (it’s on my to-do list for the generator) It was loads of fun to write and I’ve been using in Pygame and Blender projects.

I started working on a Blender wrapper for it, taking advantage of having a quick to search 2D array for object culling. Here’s some quick screen shots of my procedurally generated temple dungeon in Blender:

It’s great fun to run around in. As Agoose noted, you don’t need many assets to keep the level looking varied and interesting. And like Smoking_mirror pointed out, seeing less of the map hides repetition and makes it feel a lot bigger than it is. Using a spawner is way too slow, and a somewhat unnecessary step. Like others have said, using a 2D grid/array is much easier, it makes writing algorithms to generate content far more straight forward.

There’s a lot of good resources on creating procedural levels/mazes/content. The biggest challenge is creating an algorithm that generates levels that are fun to play (random maps aren’t fun, too rigid takes away surprise). The article I linked to above has a good discussion on this. A lot of the interest in developing my dungeon generator was in trying out various different implementations.

Another challenge I noticed was in creating the tiles, you’ve got to be very careful about how they all sit together and wrap around. And because they’re going to be repeated a lot it’s important that they look good.

On a side note, mixing indoor and outdoor lighting in the BGE is hard!

The game you were making some time ago, on an island, deals with the problems I talked about quite well. Because you’re on an island it limits the game play to that area. Procedural terrain isn’t only about moving forward and exploring new areas, if you create a compelling area people will want to spend time there, coming back to mine respawning resources or enemies. The point is that you are going to encounter the problem of repeating assets anyway, so it makes more sense to limit the game to a relatively small area rather than trying to make an endless terrain.

In that game you talked about visiting other islands too with a boat. That would be a good way to introduce different terrains, like a rocky island, a desert island, a volcanic ash island etc… with different resources and different enemies on each one. In any case, each island should be fairly small.

That is pretty nifty, but to implement in bge I think you need to run this in BPY to make really awesome stuff,

imagine growing the first terrain, then picking random points on the mesh to subdivide and then run another noise patch on,
forming rocky outcroppings, caves etc…

edit: Battery, that looks amazing!

Can I take a look at that?

I would like a videogame if it had 100 different enemies that spawn at random over random amounts of time.And also 80 different friendly npc’s that spawn at random over random amounts of time.That would assist me. And the videogame would be a procedural openworld with repetitive features.I really don’t car about repetive features in that case.

If you’re really interested in procedural generation I recommend this website.
Scroll down to the maps section for some ideas about procedural generation of maps.

A very useful one for outside areas is the Cellular Automata Method for Generating Random Cave-Like Levels.
Of course it doesn’t have to create caves, the cells it creates can be hills or lakes or forests or anything.

This is not useful for creating infinitely large areas since the algorithm reacts to the edge of the map (depending on what behavior you use for map edge results; i.e. wrapping or extrapolation or whatever).

BUT there are some more useful things to look at there besides ways of randomly generating terrain.
This article on creating fun maps is very informative. People have been making procedural generated games for a long time, and they’ve come to some conclusions about how to make them interesting and fun. Don’t forget that those are by far the most important metrics by which to judge a game.

Also, it’s always good to look at some real life examples to see what would work well and what wouldn’t:

I’ll use desert terrain as an example, since that’s something that could be made easily by a blender artist (creating enough art assets to populate a random jungle could take years for one person). Just imagine these terrains in a game.

A: Here’s some basic desert terrain. Because of the huge size of the map and large size of features as well as sparseness of details such as rocks and trees, when you stand in any one area it seems empty and boring.
B: This one has smaller features (the rocky mountains), but they are still not really interesting. There are a large number of plants, but they all look the same. Again it is boring and not a nice place to visit or explore.
C: From the air this looks good, nice rolling hills. But if you got down to a human scale I expect it would look like (A).
D: A good trick is to fill in large empty areas with impassable terrain (like lakes) now the player is restricted to the shoreline which funnels movement and creates paths, which can generate a feeling of narrative or story.
E: A mix of small and large features makes this more interesting. As does the contrast between different types of surface, the sand and rocks. Still, as I look out over the desert, I can’t think of any compelling reason to go to any of those distant mountains. It needs some towns, or lakes or rivers or ruined temples or something. But really can you imagine walking for hours across this terrain to find what looks like a temple or cave but turns out to be a shadow?
F: This is what I meant by a natural barrier. You can imagine the world continues beyond that cliff, but there’s no way to get up there so you focus on the bay instead. Could there be treasure hidden in the sand or lying behind a rock? This is staring to get closer to a human scale, it’s the sort of area that could be interesting to explore.

I think I’d go for a mix of (D) and (F), a ring of impassable outer cliffs filled with smaller depressions partly filled with areas of sand or water.

Form each depression you’d be unable to see in to the next one, so they become self contained areas. The white areas are the impassable outer “edge” of the map. Using some of the terrain generation algorithms from above this would be easy to generate. Alternatively you could invert it, making the white area sea, the blue areas impassable mountains. Or drop the height down a bit so the dark grey is also sea then the black parts become islands.

It’s pretty easy to create procedurally generated terrain, but more difficult to create a fun world for your game to take place in. You have to think about not only what it looks like, but also how it plays.

Adrians, I have coded the terrain creation last night and the results are pretty good. But that is from a coding point of view, so it would be great if you could gather some assets and textures that I can use to show you the results.

Sent from my LG-H440n using Tapatalk

Perhaps you can use these Josip.

I will get you sand and grass textures. Must pack right now. Thank you for your work. I will model tank for your project:D
P.S. Currently use thelaurent’s tree as a test object for foliage generation.

Smoking_mirror, yeah, that sounds like so, but I am first interested in making a bit alternate. Me and josip figured out that using islands can make procedural generation easy to do. Inbetween islands there is sea space which is easier to make when generating.

binary, that generator looks cool. In this case, though, I don’t have dungeons here…:slight_smile:

@BPR: Thanks man! The dungeon generator is nearly finished, and I’ll be doing a write up about it and sharing it soon. I’ll give you a heads up once its done if you like?

@adriansnetlis: Yeah, it only really does indoor environments (but can be set up to generate cities). I wanted to make a terrain generator but the biggest challenge I couldn’t figure out was manipulating verts in real time and up date collision meshes. You can use bpy in another instance of Blender to generate the mesh then libload it into the BGE (as Agoose mentioned), but to me this felt like more of a hack than a solution. I might have to give that method a try one day. But I think until you can change verts and physics in real time the BGE is probably not the best engine for procedural terrain generation. Unless anyone else has any other ideas for procedural 3D terrain?

Battery, can you look into placing gates that are required to move on? And the weapon or puzzle piece needed is always spawned on the player side of the gate? (randomly where they can get it?)

The generator is generic, and that is more of a game specific request. But it is possible with the functions it provides. Notice the orange block that connect the rooms to the corridors, they’re flagged as door tiles in the generator, and they can be rendered out as generic floor tiles or you could render them as a door with it’s own attached logic.

Also, when when creating corridors it adds each corridor tile to a list of corridor tiles. You can pick a tile from this list at random and set this to a door to have obstacles in the corridors.

Making sure the key is accessible can be achieved with the path finding function. After generating where the puzzles/locked doors would be, you’d then mark them on the 2D grid as an obstacle. Then randomly select a point in a room for the key to be place, then test that a path exists between the player and the path, if no path exists pick a new one.

Alternatively, you could generate your puzzles/doors and then use the flood fill function to find all the areas the player can reach.

You can use a single large mesh or several smaller meshes, edit vert poistions and then do reinstancephysicsmesh.
The only problem is that you are stuck with a predefined minimum/maximum size.

Alternatively I’m using tiles with a slope from n height to n+1 height. Where height is higher or lower I offset the tiles by one on thd z axis. The problem there is you can’t have anywhere where height difference in neighbors is more than 1
Also height is set to increments of 1.

@smoking_mirror: thanks for the correction! I was always under the impression that changing verts then updating the physics mesh did nothing (not sure where I got that from). I’ll have to give that a try soon (hate being back at work, just takes time away from more interesting things).

Your second idea crossed my mind too, but like you’ve noted, not being able to have sharp changes in height (like cliffs and rock outcrops or crevasses and steep valleys) is a bit of a deal breaker in my mind. I kinda picture something that ends up looking more wavy and gentle than rugged/jagged landscape. Still, since I’ve not done is so could be completely wrong. You have any screen shots of the sort landscape that method generates?

What if you combined random and procedural generation.

It makes for a good classic RTS landscape since you usually see that from a birds eye view (where sharp cliffs would look strange anyway) it’s possible to use overlay objects to make an impassable cliff on the edge of some squares for more variety.
It’s quite suitable for a tile based game but more free form terrain would be better in most cases.
When choosing a method of terrain generation of course it’s best to choose something that fits your game.

Procedural generation uses random input along with procedures or rules to create some thing that fits within the rules of your game and hopefully looks like what you could find in thd real world.

Completely random generation would just scatter trees and houses randomly around a level while making terrain that looked like pure noise.

The generation procedures help to keep trees together in forests or make villages Or make soft rolling hills, river valleys etc… but the random input makws sure they are a different shape or in a different poistion.

Some things are easier to generate than others. The procedure for creating a forest is pretty simple but the process for adding a road and river without breaking the existing terrain or blocking off parts of the level is quite difficult.

Here is a websight with a list of methods.