PROCEDURAL Terrain Generation (with Unloading) in Godot!

preview_player
Показать описание
Easy and step by step tutorial on how to make procedural natural terrain generation in Godot 4+ (I used version 4.1 here). I also explain what each element does for beginners so you can customize it for yourself! Find the code in the link below!

🌐Links:

Connect with me on social media:

Timestamps:
00:00 Intro
00:13 What is noise?
00:46 Tutorial
04:59 What does frequency mean?
05:28 Back to the tutorial
13:17 Chunk unloading
17:24 End result
17:40 Outro!

#procedural #generation #godot
game development,game dev,procedural,procedural generation,procedural generation 2d,procedural generation godot,godot,tutorial,godot 4.1,godot 4.2,easy,beginners,how to,how to make a procedural generated,procedural terrain generation, natural generation
Рекомендации по теме
Комментарии
Автор

Hey man, thanks for this tutorial! It was super helpful! One issue I ran into is some major performance loss when moving far from the spawn/ origin, even with chunk unloading implemented. What I think was happening is that the cells in the unloaded chunks were still instantiated with an invisible/ uninteractable state. I fixed this by changing the .set_cell() method to .erase_cell(0, Vector2i(x, y)). This seems to fully remove the cells and allow chunks to properly unload.

I will look into staggering the chunks being loaded and loaded also, as this seems to happen all within 1 frame causing slight stuttering.

JamesThomas-nrog
Автор

Hey i love your videos u make everything so easy to understand . Can u please make a video about making your procedural terrain generation code optimized it gets very less frames and please make a save and load system so u can place and delete tiles.

mincraft
Автор

Without knowing much about what kind of compilation or optimization happens to the code/script in godot, there are some low hanging optimization that could be done. You should move and combine any math (especially divisions) out of the loop. You could predefine the "width/2" outside of the update. You could define the tile coordinates as out of the loop as you can (x outside of y loop, y before the noise lookup etc), instead of doing all the math again for each use inside the deepest loop. You could test using a dict/map for the loaded_chunks with coordinates as the key, so checking a value would be (hopefully) logn instead of n. And check the chunk before doing the noise lookup and cell setting, which might be unnecessary. Again, not sure what godot does with the script, but i assume there isn't much in the way of auto optimization happening.

starchsky
Автор

Really nice expansion on the original tutorial - More details about how particular things work, clearer audio, more easily readable text, new features. Improves on pretty much every facet of the information that was being conveyed in slothinahat's video.

One thing I was surprised didn't make it into this is optimizations to reduce the amount of tiles being generated - With it being in the process function and having no checking, it's regenerating all the tiles in the space around the player every frame, when it only really needs to process them once.

MorseAmalgam
Автор

YOO this is really good! I’m gonna have to take a look at that chunking code

slothinahat
Автор

Amazing! Perfect balance of design+code. More please!

blarvinius
Автор

This looks awesome! I’d like to see you add certain entities for specific biomes like cactus can only spawn in the desert. Or flowers in the plains etc. I’m working on something completely different but this definitely helped my understanding of referencing the built in tile map functions 👍

greighlin
Автор

Impressive tutorial, this is much better than many other tutorials I've seen lately.

mercantilistic
Автор

Wow it has 4 views and 5 likes which shows how elite this is

DanTMZ
Автор

I wanted for my one tile to appear randomly flipped horizontally/vertically. I implemented the solution and as it turns out - this method keeps painting over even existing cells. It is a (unnoticeable on early game dev stages) hit on performance. Any ideas on how to fix it? Otherwise great video.

SSSHalt
Автор

IF at all posible can you add to when you go into water you swim?

PeaceRaft
Автор

Is there any way to add collision shapes to the land?

mailmonkey
Автор

Hello, first of all thank you for this tutorial, it's exactly what I needed. I'm a beginner and I'd like to know if there's a way of preventing the player from spawn in the water, so limiting the appearance of water around the player during the first generation I imagine... ?

remigouttefangeas
Автор

This is awesome dude very easy to follow. If i wanted to implement terrain sets so all the tiles connected smoothly with auto tiling how would I go about doing that. When I use set_cell_terrain_connect to place terrain sets it doesnt load and it throws out no errors

greighlin
Автор

Interesting, if you go away from a chunk untill it unloads and then cvomes back, will it reload as it was or as a different chunck?

davidcruz
Автор

Imagine if you tried recording this and then you realised you didn’t record the audio.

That would be pretty goofy.

Luckily that didn’t happen…

Another great video KobeDev! 👍

archwhynot
Автор

@KobeDev please, help. While It's starting, nothing is generating and i see in console "Invalid call. Nonexisten 'Vector2 constructor'" in this line of code:
if alt < 0:
set_cell(0, Vector2i(pos.x - (width / 2) + x, pos.y - (height / 2) + y), 0, Vector2(3, round(3 * (temp + 10) / 20)))
else:
set_cell(0, Vector2i(pos.x - (width / 2) + x, pos.y - (height / 2) + y), 0, Vector2(round(3 * (temp + 10) / 20)))
(in last)

legoStbok
Автор

This worked really well! I did notice however, there's quite a bit of lag once you get far enough from the origin to start unloading chunks. This causes a visual stutter due to the heavy operation of deleting a chunk within a single frame. Would you consider making a tutorial on deferring the chunk deletion to a threaded queue system? Then the chunk operations can be spread out over multiple frames, thus eliminating/reducing the stutter. I think this would make it a more viable system for practical use (no offense or anything). I have a similar worldgen system using noise, but I currently don't delete or unload chunks at all, and there is no lag or stutter, using a tilemap with 32x32 tile size @1920x1080, even after moving 500k+ tiles away, with 3 layers of tiles (fg tiles, bg tiles, and foliage). I guess Godot's tilemap system is very well optimized. Not to say that unloading isn't necessary, I just haven't coded up a system to handle it yet, which is what led me here :) Great tutorial! (And sorry if I sounded harsh, just trying to give constructive input)

ArchaicVirusStudios
Автор

Loved this tutorial however I wanted to make the tiles breakable but everytime I erase the tiles the generator generates it again, is there a way to stop that from happening?

TechGuy
Автор

you are a bit too quite, especially when compared to that outro music, but overall great tutorial

Trupen