HOW TO GODOT: Infinite procedural terrain generation

Поділитися
Вставка
  • Опубліковано 27 гру 2024

КОМЕНТАРІ • 136

  • @WindBendsSteel
    @WindBendsSteel 5 років тому +9

    Your channel is awesome, I also created an infinite terrain system for Unreal with LOD system and everything, but, Unreal has so many bugs that i decided to drop it and switch to Godot, it's so much more powerful.

    • @codat3821
      @codat3821  5 років тому

      Glad u enjoy em :)

    • @DFPercush
      @DFPercush 4 роки тому

      I could never figure out how to procedurally generate a mesh in unreal. Every other engine it's easy, but it seems like they really don't want you to do that because all the lighting is pre baked. Is your code online anywhere? Any examples you know of? I swear I looked everywhere. I'll probably still use Godot, but I just have to know, it's been bugging me for a long time.

    • @codat3821
      @codat3821  4 роки тому +3

      @@DFPercush No, the code is gone. I might create a new version and upload it to github. I know a few tricks that would make it faster :)

    • @Mil0uzz3
      @Mil0uzz3 2 роки тому +1

      @@codat3821 hello, would you have news on that ?

  • @codat3821
    @codat3821  5 років тому +22

    IMPORTANT: For whatever reason the game might crash when generating the terrain before the water. So in the chunk.gd, in the _ready function, start by calling the generate_water() and then generate_chunk()! If someone knows why this is happening, feel free too comment! :) Thanks @whoknowsyoubetter for pointing that out!

    • @lionlight9514
      @lionlight9514 2 роки тому +2

      Hey AMAZING TUTORIAL But I have 2 questions
      [1] How do I make the height of the generation a bit lower because I would like flatter generation
      [2] How do I make trees or structures?

    • @nathaos01
      @nathaos01 2 роки тому +2

      @@lionlight9514 in the chunk script line 40 or around "vertex.y = noise.get_noise_3d(vertex.x + x, vertex.y, vertex.z +z) * 80" just put something lower than 80 and its flatter

    • @lionlight9514
      @lionlight9514 2 роки тому

      @@nathaos01 Thanks

  • @deidara_8598
    @deidara_8598 4 роки тому +7

    Very interesting that you used "x,z" as a key for the chunks, personally the first time I wrote a voxel engine I used a set of equations to convert a 2d vector into an integer used to represent chunks, it was a real headache to make a system which allowed for convertion between an integer and a 2d vector. In my defense it did save memory by allowing me to use normal arrays instead of dictionaries, which was important since I was developing in WebGL and JavaScript is wayyy slower than traditional languages, but your way is far easier, and I doubt it will have too much impact on performance given this is an engine optimized for these kinds of things. Regardless thank you for the tutorial! It was really helpful for someone like be who's never used Godot before.

  • @TokisanGames
    @TokisanGames 5 років тому +12

    Great tutorial! Thanks for making the font bigger and going through each step. This is very helpful to learn. I plan to implement this in gd native and see how much faster it is.
    LOD next would be an interesting addition for the next tutorial. It won't matter on low poly, but if you increase the view distance and chunk resolution it would.

    • @elCamo12
      @elCamo12 3 роки тому

      been trying that the whole weekend... but it seems gdnative has issues with nodes instantiated from gdnative.
      would be nice to know if you got it working somehow.

  • @JackieCodes
    @JackieCodes 2 роки тому +5

    omg your keyboard sounds amazing, what is it? btw awesome tutorial!

  • @dimred4972
    @dimred4972 4 роки тому +6

    Hi! I have all the code from 18:35 working with no errors but no terrain has generated. any ideas?

  • @rysiekgremory2379
    @rysiekgremory2379 2 роки тому +2

    i just gave you 1000th like under this video :D

  • @tranceemerson8325
    @tranceemerson8325 5 років тому +1

    Very interested in seeing what Godot is able to do. thanks for being very plain and straightforward.

  • @MangoJones139
    @MangoJones139 4 роки тому +1

    Thanks for for your tutorial. I helped me getting started with a voxel based terrain generator in Godot + C#

  • @bloglifenguyen3028
    @bloglifenguyen3028 2 роки тому

    Your tutorial is dope :v hope you doing it more

  • @thelukeaaron
    @thelukeaaron 4 роки тому

    Thank you for another great tutorial! Exactly what I was after for my current project. I noticed you've not posted anything for a few months so hope you are well!

    • @codat3821
      @codat3821  3 роки тому +2

      Im doing well thanks. Kids and stuff going on in life hehe

    • @thelukeaaron
      @thelukeaaron 3 роки тому

      @@codat3821 Glad you're well 👍

    • @codat3821
      @codat3821  3 роки тому

      @@thelukeaaron Heh thanks. i hope ur doing fine aswell. what are u working on?

  • @MirceaKitsune
    @MirceaKitsune 4 роки тому +3

    Planing to use this concept to generate full planets. Similar to the other project you posted, except I'm planning to make them a lot more high-poly with detailed shaders as well as allowing the player to walk on and around them. Should have the base concept handled... more worried about calculating the sky and sunlight settings based on view position / angle lol

    • @dionbridger5944
      @dionbridger5944 3 роки тому

      So, did you end up doing that?

    • @MirceaKitsune
      @MirceaKitsune 3 роки тому

      @@dionbridger5944 I played with the idea a bit and got something working a while back. Haven't messed with Godot again yet recently.

  • @ajomeara9814
    @ajomeara9814 3 роки тому

    Great Tutorial learned a lot, cheers.

  • @hooman1439
    @hooman1439 3 роки тому

    "SUBSCRIBE TO HELP ME GET RICH" straight to the point, I like it

    • @codat3821
      @codat3821  3 роки тому

      never got rich though :(

  • @ayushmaurya9556
    @ayushmaurya9556 Рік тому +1

    POV: You were looking for its Github Repository for easiness but got nothing

  • @ungodlyfaded
    @ungodlyfaded 5 років тому

    Great tutorial, will have to check out the last one and see what ya did before.

  • @w84death
    @w84death 5 років тому +1

    Thanks! I need this for next project.

  • @postal83
    @postal83 4 роки тому

    Thank you, excellent tutorial.

  • @qwertystop
    @qwertystop 4 роки тому +2

    I'm uncertain about the safety of this threading approach - it doesn't allow one chunk to start being added while another is still being processed, which is good, but it just drops the attempt instead of queuing it up if one is still in-progress, with an end result that I don't think it can generate more than one chunk per _process call. And looks like it's possible to start adding another chunk after load_chunk has finished, but before load_done has completed, in which case the wait in the load_done from the first chunk would end up waiting for the second call to load_chunk to complete? Not sure of the results, if that happens.

  • @ignacio3460
    @ignacio3460 5 років тому

    Thanks so much for making this! It'd be really useful if you made a tutorial for loading the chunks at different LODs :)

  • @hashkeeper
    @hashkeeper 3 роки тому +2

    can you link this on github or a personal website repository so we can download these files?

  • @Theaksten
    @Theaksten 5 років тому +9

    I liked the tutorial, I followed it exactly and watched it twice, but the terrain never appears. Does anyone have a sample they can share? I must be making some minor logical mistake somewhere!

    • @codat3821
      @codat3821  5 років тому +1

      Hello! Did u solve the issue? Sorry for late answer! :)

    • @redeyeblues3723
      @redeyeblues3723 5 років тому +2

      @@codat3821 I have this same issue.

    • @codat3821
      @codat3821  5 років тому +2

      @@redeyeblues3723 He contacted me on discord. And hes problem was his _ready function, he misspelled it. So its very hard for me to isolate ur problem :/

    • @hyperbhavik
      @hyperbhavik 4 роки тому

      I also have same issue

    • @nikluz3807
      @nikluz3807 4 роки тому +8

      here is the code for this tutorial: github.com/nikkiluzader/godot-3d-procedural-generation/tree/master

  • @hashkeeper
    @hashkeeper 3 роки тому +1

    this is amazing. Could you do a video that is the most stripped back version possible -- like just a basic plain object (the one in blender) repeating? that would probably get an insane amount of views, if you made the defacto godot 3d plain repeating video tutorial. but that's also a specific request so i get it if not

  • @epicz3970
    @epicz3970 2 роки тому +1

    How do you make structures?

  • @skrypciarz5974
    @skrypciarz5974 3 роки тому

    Thank you. It is very useful.

  • @andreasfunke843
    @andreasfunke843 5 років тому +4

    Great tutorial! Thanks you.
    I have one question : I have no experience with threads in godot, but shouldn't you use mutexes for the dictionaries, since you read and write to them in different threads?

    • @hikerwolfspaine8200
      @hikerwolfspaine8200 5 років тому +1

      I did a quick check and it looks like adding, resizing, and removing is not thread safe. Writing to existing entries may be fine. docs.godotengine.org/en/3.1/tutorials/threads/thread_safe_apis.html

  • @Looki2000
    @Looki2000 3 місяці тому

    what if my map is not infinite and I just want to generate all the chunks over time without having to regenerate them? Can I simply add all chunks as children and hide them when far from the player? I'm not worried about memory. I'm only worried that these hidden chunks may still cause some slowdown.

  • @adamoolah
    @adamoolah Рік тому

    i have a problem- when i walk around the map and hit a hill the charecter just flies in mid air and doesnt stop how do i fix that

  • @markflakezCG
    @markflakezCG 4 роки тому

    The Terrain doesn't load in my case. The only error i get is this:
    E 0:00:00.543 _create_instance: Condition "r_error.error != Variant::CallError::CALL_OK" is true. Returned: __null
    modules/gdscript/gdscript.cpp:127 @ _create_instance()
    Does anyone has an idea what's the problem?

  • @decisive2242
    @decisive2242 4 роки тому

    This is pretty cool

  • @alexandrepinto4549
    @alexandrepinto4549 5 років тому +2

    Hey dude, I am getting this problem where instead of the sand grass and water just divide throughout the map the materials just overlays one to another

    • @codat3821
      @codat3821  5 років тому

      hit me up on discord, so i can have a look. gillberg at Godots server! :)

  • @andrewparsons3277
    @andrewparsons3277 5 років тому

    While trying to run it for the first time while at about the 20 minute mark in the video I received 2 errors.
    E 0:00:01:0926 Node not found: Rotation_Helper/Camera
    scene/main/node.cpp:1382 @ get_node()
    Player.gd:19 @ _ready()
    which when clicks takes me to line 19 of the player script
    and
    E 0:00:01:0928 Node not found: Rotation_Helper
    scene/main/node.cpp:1382 @ get_node()
    Player.gd:20 @ _ready()

    • @codat3821
      @codat3821  5 років тому

      So.. as the error message says "Node not found". So maybe you have forgot to change the name parentnode (of type Spatial) of the camera? :)

  • @JustAnotherAlchemist
    @JustAnotherAlchemist 4 роки тому

    *Many questions.* ... I'll ask one for now.
    Is there a particular reason you are sampling noise using a 3D _input_ vector?
    I have this tut figured out, and my own code is working, but I've settled on using the method "get_noise_2d" to sample the noise for setting the terrain verts Y axis. Since one only needs an X and Z to get OpenSimplex (or anything like perlin noise) to reliably produce samples that are continuous over the field, this seems like the more correct way to go about the task.

  • @nathaos01
    @nathaos01 2 роки тому

    Can you tell me why the heck generating chunks is so laggy for me? In your vid its so smooth and fast..
    Anyway its a great tutorial man keep it up :D

  • @finlayl2505
    @finlayl2505 4 роки тому

    You can use vector2 as a key in a dictionary and it is faster. I don't know if this was possible when the video was published.

  • @lionlight9514
    @lionlight9514 3 роки тому +1

    Hey AMAZING TUTORIAL But I have 2 questions
    [1] How do I make the height of the generation a bit lower because I would like flatter generation
    [2] How do I make trees or structures?

    • @jesielr.lofhagen643
      @jesielr.lofhagen643 2 роки тому +1

      you can change the noise.period and
      noise.octaves attributes to change the terrain properties, also the noise multiplier in the Chunk class, in the video he puts a constant of value 80

    • @lionlight9514
      @lionlight9514 2 роки тому

      @@jesielr.lofhagen643 Thanks

  • @makoshark40
    @makoshark40 3 роки тому

    hmm nice i do want a limited world size tho quite big ill have to find that out now.. also i need to find out how to generate more island like lands instead of these tiny mountain islands

    • @skreet7251
      @skreet7251 2 роки тому

      folllow his low poly ttutorial

  • @jesielr.lofhagen643
    @jesielr.lofhagen643 2 роки тому

    Did anyone found a more performant solution? I'm not used to multithreading but I did add new threads and it did not get much better, what if it was in C#?

  • @alexkoehn5036
    @alexkoehn5036 7 місяців тому

    doesnt work in godot 4, i dint really know what I'm doing, i got it to run, but the window is just grey

    • @Efxli
      @Efxli 4 місяці тому

      i dont think you set up a camera so you wont be able to see anything

  • @monopoly2170
    @monopoly2170 4 роки тому

    Is the map persistent? You may have mentioned it and I missed it.

  • @ohiasdxfcghbljokasdjhnfvaw4ehr
    @ohiasdxfcghbljokasdjhnfvaw4ehr 2 роки тому

    at 17 minutes when you tested it for the first time, mines broken.
    I wish you tested it after each code to show what each part is adding, and put the scripts online so we can compare.

  • @ciccioculone1
    @ciccioculone1 3 роки тому

    oooooooooooooooooooooooooo this is so cool... everything works fine, just it doesn't works smooth as intended.
    Do you guys know why changing chunk_count the frame rate drops?
    As far as I understand secondary threads should manage everything leaving the main thread free to fly, but it works only with a certain ammout of chunks.

  • @pivotgamer4569
    @pivotgamer4569 3 роки тому

    how can i use this to add grass spawning also

  • @Megalomaniakaal
    @Megalomaniakaal 4 роки тому

    All I get is a single tile being generated, did you paste in some code during some sped up segment that I might have missed? This is why I think it's good to have finished code to check against, as books usually include.
    I mean as I move around others are spawned, but I see them spawn for you even when you are stationary in a grid like fashion, I just get the central one.

    • @codat3821
      @codat3821  4 роки тому

      No. I think its all there.. ull have to either do some debugging or rewatch the vid. Are the chunks being generated from the thread? If so, do they get added to the scene? If so, on the right position... and so on :)

    • @Megalomaniakaal
      @Megalomaniakaal 4 роки тому

      @@codat3821 Derp, I found my issue. Last night tiredly I must have missed that I added the division by chunk_size inside of the int casting in the chunk updating method. ;p

    • @Megalomaniakaal
      @Megalomaniakaal 4 роки тому

      I'm thinking it might make sense to maybe implement geometry clipmap for tterrain instead?
      hhoppe.com/proj/geomclipmap/

  • @LordDanielGaming
    @LordDanielGaming 5 років тому

    Pretty good. There are other performance improvement can you recommend? Does it even heavy on the cpu?
    Edit: you wrote in 5:15 there is a link in the desc, but you forgot to add it :D

    • @codat3821
      @codat3821  5 років тому +6

      U can absolutly improve performance.. from the top of my head u can first try to avoid type casting (as we do in the keys in the dicts). U can also change the worldscript to not update the chunks every frame and instead only update the chunks whenever the player enters a new chunk in the grid.. :)
      Thank u for pointing the descriptions thingi!! :)

    • @alexritchies
      @alexritchies 5 років тому

      @@codat3821 Hi! just as a follow up question to this, is there any reason you know of why we couldn't just use a Vector2 for the keys instead of type casting? would that be better performance-wise?

  • @stevepblair
    @stevepblair 5 років тому

    This was really great, thanks!
    Question though: After the player moves in one direction and the chunks behind them are removed in the clean up function, what if the player turns around and goes back to that same area? Wouldn't your code generate brand new terrain in those previously visited areas?

    • @codat3821
      @codat3821  5 років тому

      Steve Blair yes when the player moves back or anywhere else, the chunks are generated. Thata the whole point, otherwise you would run out of memory at some point.:)

    • @stevepblair
      @stevepblair 5 років тому

      @@codat3821 Right, that makes sense. I was thinking it would be nice to store those chunks to reload them when the player goes back, but with an infinite amount of chunks, that could go pretty badly

    • @Bollalillo
      @Bollalillo 5 років тому

      @@codat3821 If you can't have saved chunks, then what's the point really. You've made an awesome video showcasing how to essentially make minecraft in godot. Going back to previous chunks where u f.ex have made a structure would be awesome. If not this would only be useful in an exploration game where backpedaling isnt nessesary

    • @psionicxxx
      @psionicxxx 5 років тому +1

      Chunks are not generated randomly, he uses a noise map to generate them. The terrain information is kept in the noise map and the visited chunks will be always generated according to it.

    • @Ex0dus111
      @Ex0dus111 4 роки тому

      You can still save stuff.
      Say you dropped some loot in an area and went back to it later. All you would have to do is store the external objects somewhere, and replace them based on their transition properties once the chunk is regenerated. Save the key of the chunk they belong to, and check keys for "lost items" whenever you generate a new chunk.
      Not hard at all.

  • @whoknowsyoubetter
    @whoknowsyoubetter 5 років тому

    Hey, awesome tutorial! Just a quick question, for whatever reason when I added water and run the project, the script would try to free main World node when the loading thread would start generating the chunk directly under the camera. Commenting out either generate_water() or generate_chunk() in chunk.gd prevents it from crashing. The error is: Attempt to call function 'add_chunk' in base 'previously freed instance' on a null instance.

    • @whoknowsyoubetter
      @whoknowsyoubetter 5 років тому

      When I switched lines around and started calling generate_water() first, it somehow solved the issue. Weird!

    • @codat3821
      @codat3821  5 років тому

      whoknowsyoubetter hmm that is weird. Ill have to lool into that and get back to u asap :) out golfing atm ^.-

    • @codat3821
      @codat3821  5 років тому

      @@whoknowsyoubetter well i also encountered that problem when i fooled around a little.. but as u said, generating the water first solves the problem. Thank u dude! :)

    • @TokisanGames
      @TokisanGames 5 років тому

      I experience this often in another Godot project. Maybe it has to do with threading and something is getting called before it is loaded, but only sometimes.

    • @AustinRSeabolt
      @AustinRSeabolt 5 років тому

      @@TokisanGames I get errors like this every time I try to implement threading. Not sure what I'm doing either because I'm not doing anything that should cause that. Let us know if you figure it out

  • @ekaterinavalinakova2643
    @ekaterinavalinakova2643 4 роки тому

    Some questions: How do you layer additional 3D noise when it comes to modifying the geometry? An idea I have for procedural planets is the closer you get, the more subdivided the areas of the planet are, and another layer of noise modifies the geometry of the land more, giving the landscape more realism. And the closer you get, the more subdivided it gets, and another layer of noise further modifies the geometry. Ultimately, the closer you get, the more detailed that area you are looking at becomes. And as you move further away, the reverse happens: things get simplified the further away you get. In order to create life sized planets this process is probably going to be necessary. Another thing that is important is being able to give some degree of randomness to the colors of the landscape. I want to be able to use noise to give variety to the greens.

  • @ShadowIzLurken
    @ShadowIzLurken 4 роки тому

    class_name chunk does not work

  • @heyimamethyst
    @heyimamethyst 4 роки тому

    Does anyone know how to generate other things like trees and grass in with the infinate terrain?

    • @shwetanksingh2156
      @shwetanksingh2156 4 роки тому

      Noo

    • @vladimir-sama
      @vladimir-sama 3 роки тому

      Hello, have you found this? I tried it and chunks do not load, but maybe you could use several seeds: one for each type of object, not depending on randomize and randi or randf function. I will try this today

  • @tazz7390
    @tazz7390 3 роки тому +1

    Very cool tutorial! Although, I have a question. When you go far away from a chunk and it unloads, when you come back, does that chunk look the same? If so, why? Is that information stored somewhere or is it just generated again?

    • @codat3821
      @codat3821  3 роки тому +1

      Hi dude. The only information stored is the data from the noise map. and yes, it will look the same once u revisit it. though all chunks are regenereated. :)

  • @theokendall5386
    @theokendall5386 4 роки тому

    nice tutorial. had a bit of trouble getting it to work with multiplayer tho

  • @TheGamingWiccan
    @TheGamingWiccan 5 років тому

    Can you please tell me how i would get the terrain looking a bit more cubic like in minecraft?

    • @codat3821
      @codat3821  5 років тому

      Then you will have to use a whole different approach, called voxel system. This can be acheived with godots gridmap for example :)

  • @finniganroverfield1753
    @finniganroverfield1753 2 роки тому

    very good, however there is an error always popping up on vertex.y = noise.get_noise_3d(vertex.X + x, vertex.y, vertex.z + z) * 80 where it says that all vertexes are not in the current scope?

  • @perebraco
    @perebraco 5 років тому

    Finally

  • @cringedmossy5260
    @cringedmossy5260 4 роки тому +1

    so long I have done so much and am only 5 minutes into the video, my back hurts, Ahhhhhhhhh!!!

  • @boro6908
    @boro6908 Рік тому

    Are you like Swedish?

  • @hyperbhavik
    @hyperbhavik 4 роки тому +1

    I am stuck on debugging

    • @nikluz3807
      @nikluz3807 4 роки тому

      here is the code for this tutorial: github.com/nikkiluzader/godot-3d-procedural-generation/tree/master

  • @g1n059
    @g1n059 3 роки тому

    what is a thread?

    • @codat3821
      @codat3821  3 роки тому +1

      Simply a different process running in prallel with the main one. Makes it possible to do multiple things the same time. As we do here, play the game while loading new chunks. Without threads, loading s chunk would make the game unplayable :)

  • @nv7213
    @nv7213 4 роки тому

    Does anyone have the project files available for download?

    • @nikluz3807
      @nikluz3807 4 роки тому

      here is the code for this tutorial: github.com/nikkiluzader/godot-3d-procedural-generation/tree/master

  • @jabisagat2369
    @jabisagat2369 5 років тому

    Awesome thanks...

  • @bash141
    @bash141 3 роки тому

    brooo thxxxxx

  • @bigbird612
    @bigbird612 4 роки тому

    im having a problem
    ive written most of the lines of code but it doesn't recognize some of the words i place
    how can i fix this?

    • @nikluz3807
      @nikluz3807 4 роки тому +1

      here is the code for this tutorial: github.com/nikkiluzader/godot-3d-procedural-generation/tree/master

  • @dreamhollow
    @dreamhollow 3 роки тому

    This is a really great tutorial, but I think I messed up on the chunk generation and my computer nearly burned itself out trying to generate terrain.
    Is there a better way to force a hard limit on generation so it doesn't overflow?

  • @amadeus3341
    @amadeus3341 4 роки тому

    "Invalid call to built-in function 'range'. Expected 3 arguments." Doesnt work

    • @amadeus3341
      @amadeus3341 4 роки тому

      Also when i use the Script im not able to move or look around anymore.

    • @nikluz3807
      @nikluz3807 4 роки тому +1

      here is the code for this tutorial: github.com/nikkiluzader/godot-3d-procedural-generation/tree/master

    • @amadeus3341
      @amadeus3341 4 роки тому

      nikluz ty bro

    • @nikluz3807
      @nikluz3807 4 роки тому +1

      @@amadeus3341 no problem =) I need to make some improvements to the player movement, but this is the exact tutoral code with no changes

    • @amadeus3341
      @amadeus3341 4 роки тому +1

      @@nikluz3807 Yea i literally found out why it didnt worked. I forgot the parameters at range LMAO

  • @laurinhofer7243
    @laurinhofer7243 4 роки тому

    Are you now Rich

  • @ac11dc110
    @ac11dc110 4 роки тому

    my question is: why dot you want to get rich?

    • @codat3821
      @codat3821  4 роки тому

      I want to afford all ducktape in the world

  • @GrungeBro1990
    @GrungeBro1990 5 років тому

    would been nice if done with visual scripting also!

  • @bluepixelmusic9463
    @bluepixelmusic9463 5 років тому

    i subscribed to help you get rich,
    but who is rich?

    • @dari0us
      @dari0us 3 роки тому

      Hope Rich is okay. Wonder if he ever got him.

  • @melindamassey14
    @melindamassey14 7 місяців тому

    Yeah my engine didnt look like yours. But all you guys on here do this! I had no custom tab or kinetic body. I think you all like to frustrate us!

  • @yusarimahubara
    @yusarimahubara Місяць тому

    The godot open world course from zenva academy literally copied your code