RANDOM MAP GENERATOR - EASY UNITY TUTORIAL

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to Blackthorne prod I'm Noah now many games use random level generation as a way to increase replayability by making each restart fresh and exciting and preventing the player from simply learning our particular level layout by heart and quickly getting bored in roguelikes it reinforces the tension of permanent death because players know they'll never get the exact same world twice so dying not only means losing a character and progress but also an entire world whatever your reasons are for wanting to create a randomly generated world or level in this beginner unity and c-sharp tutorial I'll bring you through the process of creating a simple random level generator by the end of the video you should end up with a system that randomly spawns characters and environmental pieces at different locations now this method will also leave you a lot of control over your level generation so say you would like templates mostly composed of trees and flowers you could do that same for a world populated mainly by characters now note that I'm using 2d assets but absolutely everything demonstrated in this tutorial applies for 3d with that said let's get started so I have this new unity project opened up and inside my scene I have a couple sprites that I quickly made using Adobe Photoshop these are the asset I will be randomly spawning around my game world first of all I need to make prefabs out of these sprites so I'll create a new folder named prefabs and simply drag and drop each sprites into that folder I can then delete them from my scene next up I'll create a new empty game object reset its transform and call at level templates zero one I'll also give it a little red gizmo so we can clearly see it in our scene I'll then make another empty game object call it spawn points give it a yellow gizmo and make it a child of the level templates game object i will duplicate this spawn point several times and place them around the red gizmo each spawn point as you may have guessed will spawn a random object such as a tree character or flower all right awesome let's now treat a simple c-sharp script alcohol level generation I'll begin by making an array of game objects now simply call objects' we will put in this array all objects that we would like to potentially spawn in my starts function I'll then make an interval called R and for random and set equal to a random number that has a value between zero and the amount of game objects in our array Nia all that's left to do is spawn a random objects from our array using this int variable to do so simply type instantiate and in V parentheses States what object you would like to spawn in my case I would like to spawn the object in my array that has an index equal to my random variable we then must choose a location for the newly spawned object I'll give it the transform of the object with this script attached to it and then I'll finish up by typing quaternion dot identity meaning I would like my object to spawn with no rotation heading back into unity I will grab all of my spawn points drag and drop the script onto them and then lock the inspector while now do is drag and drop my trees flower and characters into the objects iranian and by pressing play you will see that each spawn point will randomly generate a game object if I hit play again you will see that things are again different and I can hit flee again and of course things are again set up in a different way however this is still a little limited and very quickly players will notice a repetitive pattern where we must now do is create more than one level template so I'll make a prefab out of mine level template 0 1 and then name it level template 0 2 and to make a new prefab out of that now I would like this level templates to spawn and mainly trees in clumps so I'll delete all spawn points except 1 refresh the objects array and drag and drop both of my trees twice in the iranian as well has one flower now there is 4 chances out of 5 that what comes out of this spawn point is a tree and one chance out of 5 they spawns a flower I'll then duplicate this several times placing my spawn points in clumps you can now make as many level templates as you like just keep in mind that giving each spawn point several objects is key to convey a random feeling to the world I can now create a new empty game object call it level generator drag and drop the level generation script onto it and instead of dragging dropping trees and characters into the array I can drag and drop my level templates now when I hit play this level generator game objects will spawn a random level templates which in turn with all its unique spawn points populates the world with characters trees and flowers I can of course duplicate this level generator empty game object place each one at a nice distance apart so templates don't overlap and very quickly we can get a large randomly generated world and for those of you having follows my unity dev vlog on my top-down shooter set in the mind the fire of belief you may be interested in knowing that this is the system and that I use to get my randomly generated world up and running so I hope you enjoyed the video and will be able to use this very simple method in your own creations as always thanks so much for watching don't forget to hit the like and subscribe buttons and make my day that much more wonderful by the way you can also join the blackthorn prod discord server and chat with fellow game creators of our art unity programming and more with that said stay tunes Cheers you
Info
Channel: Blackthornprod
Views: 154,847
Rating: undefined out of 5
Keywords: blackthornprod, noa calice, indie game dev, random, map, level, generator, beginner, simple, basic, C#, programming, easy, quick, tutorial, unity, game dev, how to, create, make, procedural, rogue like, binding of isaac, spelunky, dungeon, generation, instantiate, arrays
Id: D4EOgZyNk-k
Channel Id: undefined
Length: 7min 21sec (441 seconds)
Published: Tue Feb 20 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.