How to use Perlin Noise in Godot | Game Dev Tutorial 9

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome friends in this tutorial I'll start by introducing you to Perlin noise and how it's used to make games then we'll hop into Godot and I'll demonstrate how easy it is to use Perlin noise in your projects without further ado let's get to it this is an image of random noise each pixel is independent from every other pixel and can have any value 1 pixel and its neighbors can have wildly differing values and this is Perlin noise Perlin noise is random but unlike true random noise its values change gradually like a gradient and are connected continuously when moving from one pixel to the next Perlin noise is perhaps most famously used for generating procedural terrain in fact it forms the basis of the randomly generated worlds of Minecraft but generating terrain is far from its only use it can you be used to generate an endless number of things from populating asteroid fields in a space sim game to carving out cavernous water caves at the bottom of an ocean in my game prototype project route Perlin noise is used to generate these spirally organic looking routes that must be avoided as the player falls in my opinion Perlin noise is an essential tool every game developer should have in their toolbox so here's a crash course on what you need to know to use Perlin noise in Godot this is a 2d image of Perlin noise on the horizontal dimension there is the x-axis and on the vertical dimension is the y-axis for simplicity let's say each pixel in this image can represent values between negative 1 and 1 where values of 1 are pure black and values of negative 1 are pure white and of course intermediate values are between black and white if we input two numbers into this purlins space an x value and a Y value we get back a single number the purlins value which exists at the intersection point in the 2d purlins image if we give x and y values that intersect in a black region the return purlins value will probably be a positive number between 0 and 1 if we choose X and y values that intersect in a white region the return purlins value will probably be a negative number between negative 1 and 0 or if we keep the Y value constant and change the x value over time the purlins value will change over time randomly randomly yes but also gradually in continuously setting this up in Godot is actually very easy Godot has a built in version of the Perlin noise algorithm in the form of a resource called open simplex noise the open simplex noise resource can be used in a similar way to how we use the curve resource in my how to use curves tutorial let's jump into Godot and I'll demonstrate how simple it is to use Perlin noise I've created and saved a new scene that includes a root spatial node called game a camera and an outlined unshaded test sphere in this game we want to move the sphere up and down randomly if we simply tried to move the sphere up and down using GD scripts randomize functions the sphere would just appear to jump around the screen to get smooth random movement will connect the spheres height property to a Perlin noise resource on the scene root i've already prepared a script for us to start with the sphere variable is a reference to the sphere instance the amplitude variable controls how far our sphere can move up and down the speed variable controls how fast the time variable changes and in turn how fast the sphere moves up and down in the process function the speed value gets added to the time variable every frame to add an open simplex noise resource to our script we can type export open simplex noise variable Perlin noise then we need to create a new instance of the resource click on the game root node and in the inspector find the newly exported variable Perlin noise in the Perlin noise field click empty new open simplex noise clicking on the new resource will open and close a list of properties that can be used to change how the purlins algorithm generates the noise more on that later back in our script to get a purlin value we need an X and a Y value our time variable serve as our x-value and will keep the y-value constant at zero the opened simplex noise resource comes with function called get noise 2d if we give this function our x and y values it will return a purlin value Perlin noise is actually multi-dimensional and the open simplex noise supports noise in four dimensions but here we'll just stick with 2d like our example image now that we have a a purlin value we can use it to move our sphere up and down at the moment the purlins value is always between negative 1 and 1 to get our sphere to move up and down beyond just one unit we can multiply the purlins value by our amplitude variable finally we set the resulting value to the Y component of the spheres translation vector and with everything in place we can press f6 to run the scene as time goes by our sphere should move smoothly and randomly up and down but one sphere really isn't enough to visualize the true power of Perlin noise if I add 1700 spears that might just do the trick in this demo scene the spheres move up and down within the range of the amplitude just like our tutorial scene except here the spheres changed green for positive purlins values red for negative purlins values and white sneer values of zero as our time variable changes the noise generated by the purlins algorithm moves across the spheres in theory the algorithm will continue to generate an infinite amount of random noise so long as our time variable doesn't get so large as to run out of memory which incidentally is the cause of the farlands behavior in minecraft using this demo the properties of the open simplex noise resource can be changed and viewed in real time going into detail about these settings is beyond the scope of this tutorial but you can play with them and watch the effects however I will say that the seed property is the value that the entire algorithm is based on changing the C value completely changes the Perlin noise values that are subsequently generated this tutorial and the demo project can be downloaded from the Dave the DEP github page linked below if you'd like to follow the projects I'm working on I'll be posting regular dev vlog updates to my Twitter account also linked below well that'll do for this tutorial if you learn something interesting consider hitting the like button and if you think I've earned it subscribe and hit the bell icon to join our growing community hope to see you next time until then happy Debbie [Music]
Info
Channel: Dave the Dev
Views: 4,701
Rating: undefined out of 5
Keywords: Godot, Godot Engine, Game Development, Perlin, Perlin Noise, Perlin Algothrim, OpenSimplexNoise, procedural generation, Game Dev
Id: Fc5SSejIrCU
Channel Id: undefined
Length: 7min 20sec (440 seconds)
Published: Sat Oct 05 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.