Level Design and Click to Move | Making a Simple RPG - Unity 5 Tutorial (Part 1)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back we are going to start the simple RPG and you know e5 series off with setting up the scene we're going to design a very small level using some assets from the asset store just one package and it comes with all the models you saw in the introduction video and a ton more models but we're gonna keep it very simple with just a few things to give us something to play around with and then we're going to set up the character movement for the player in this episode as well so it was going to start with that first of all I'm going to go to window I'm going to open up the asset store just like and grab those models real quick and in the search bar I'm going to type in low poly now it may not be where it is now for me depending on when you're watching this so I'm going to leave a link in the description so you can grab these if you want to follow along and I'm just going to import there's a lot of models in here that's great for prototyping and I think it's going to be nice to have something it looks a bit more complete in this series and what I'm going to do is I'm going to show you how I'm going to throw the level together it's very simple I'm going to be doing just dragging and dropping prefabs from the folder out into the scene view and set up a couple lights and that's going to be pretty much it so I probably fast-forward through a lot of that just to speed up the process so I want to close out the asset store and Here I am in the scene view my directional light we'll leave it like it is for now but I'm going to go ahead and add an empty object I'm going to call it environment and we're going to put our level inside of this empty object you could break it down how everyone if you have sections of your environment that you want to be on different objects do it however you want to but for this it's going to keep it all in the environment and I'm going to start out first of all with just a ground and I'm going to create a cube for that it's going to use a cube interesting and the cube I'm going to just scale it up and see what do we think we'll do 15 by 15 for now just something to work with grab my camera and I'm going to pull it up a bit so we can see the ground rotate it just like that there we go and I want to call this ground and I want to go in my assets folder look we can create a folder for materials that we're going to define and the first material want to create material gonna call it ground ground grass make it a green color will match this to the grass that comes in the asset but for now we'll just do that and drop it on ground just like that I'm going to pull my camera up just a bit because you're seeing the edge of the world there and we'll move all this around later on I'm sure so with the ground set up I'm going to go ahead and grab it and scale it a bit more just like that right there pretty good and going Milo my little Polly low poly folder and I'm going to grab a few things the first thing I want is we're going to set up the cave that you saw in the demo just search for cave want to grab it drag it out and place it in the map here I noticed it's gonna be too big so we're going to scale the ground up a bit more too but let's just place this we're going to scale things to the cave keep the cave at the scale it's at and to scale everything else to the cave it depends on your assets how you're working with it but this is going to work fine for us just like that and I'm going to bring the cave down a bit you can see it has a ground plane we're going to hide that ground plane under our ground plane just like that and rotate it a bit more just like that and in the demo we had a dirt ground in the cave I'm going to type in dirt show the dirt things cave dirt so we just had uneven ground we'll use that and we'll place it in the cave and we're going to scale this up so it goes in the cave and looks fine then raise that up and I would hope you would spend more time on yours then I'm spinning on mine but we just wanted to look ok and now we want the dirt mountain but it's dirty mountain that's grass I don't want to grass oh here it is dirt heel I'm going to place it off to the side of the cave here so you rotate it around do something like this is fine bring it in scale it up a little bit and lift it up a little bit looks pretty good and then I'm going to throw I'm kind of just winging this I don't really know how I wanted to look now I know we had before but just have to look exactly the same does it want to grab this pine tree scale it up and clearly we're not going for realistic style or anything so we don't have to do anything to scale it doesn't really matter we were just doing and however we wanted to be done it's gonna draw the first websites didn't let me see you slow this is the true thing just goes yep Demetri so I'm like that and great and you can set up your snaps to work with this so you can snap the objects together but I'm just going for a rough layout I'm not too worried about it well them to do then I'm going to duplicate this one and it's going to rotate it appear just like that and I'm going to grab all these holding shift just like that grab it and drag it into my environment there we go and add 20 grams of you will have rest catch - at least my man Frank Messer that's what it's on littered once per your podium just nice burn whisper there big flower doing a rap splint here doesn't man doesn't it okay this would be enough for now and I want to also mess with the lighting a bit because I do not like the lighting we have so we're gonna make it like a night scene I'm going to do a deeper orange just like that I want to turn the intensity down just a bit not too much and I want to duplicate this directional line I'm going to go to it and notice how my orange light is see the rotation of it I want to rotate this one that I've just created a bit this way let's see we're going to make this like a feel light so go do that we're going to turn off shadows because we just want that because I feel like not cast any shadows I make this a deep purple just like that turn the intensity down just a bit and turn you down this one just a bit see something like that and I'm going to go to my window I'm going to go to the lighting and in here want to mess with a few things first of all I won't fog on and it's going to be exponential squared the density is going to be whoo no it's me like point zero two and it's going to be a deep purple and I'm going to turn the ambient intensity down just a little bit like the ambient source for now let me get a color and it's going to be a C or D want this to be I am just messing with the mood of my game at the moment there's nothing important about this whatsoever I just in find just find this fun we make it's like a deep purple and then we can increase increase the lighting on that decrease the lining up in this purple here you don't exactly degrees with you and one thing I want to do is we're going to mess with this in a little bit when we work on me and be an occlusion and whatnot but for now what I want to do is I'm going to get the light it's going to be on our lamp post here if we go to our lamp post notice has three for materials one of the tutorials is the lighting on the lamp itself so I'm going to select that I'm going to go to emission we want this to have like a light source of its own which we will put a light in it like a spotlight in it in a second but I also want it to emit right so for if I want to do that I go to my main camera I'll turn HDR then I want to go back to my lamp post real quick go down to a mission want it to admit nice a deep orange color just like that and we're going to make it above one which is how we're going to create a glow effect when we work with the bloom we can set the threshold of a glow so it doesn't affect anything below one but anything above one notice it now requires HDR we're going to have like a glow effect around it which will be pretty cool so now to do that what I would do is I would go I want to import the standard assets and all I want the effects package it's all the built-in image effects and we're all pretty good honestly so going to support all of those alright now that they are loaded in I want to go to my standard assets and this is not quick and dirty but you can play around with this and get whatever effect you would like I'm just going to grab the bloom just a standard bloom and drop it on my main camera notice you already get a glow effect on that because the threshold it's pretty low I want to go too high we want to get a nice glow effect around that increase intensity on the bit if you wanted to you doesn't ever you want to do it we're also going to have the crystals that you saw in the demo in the cave and that's a desert real quick just like that and I'm going to grab what is place and put that in environment and now I have my crystals here and what I should have done actually is each one has a material on it and I want to update this material the same way we did last time and I'm going to make it a nice blue just like that and once again I can increase this to increase the amount it affects the gloom but I'll just do a nice subtle glow just like that I would also like to grab the color correction curves again not important but it's fun for the level design drop it on my main camera and I'm going to see the reds here got a bit too much red right so it's knock out some of the red just like that and I like to increase some of the blues I don't really know too much Joe is alluding to I mean that's good to see there something like I just play around with it and get what you like and I'm going to grab going to grab this grab the ground grass texture and what I would like to do is if I can come in close on these grass blades here the grass oh wow that really changes the the whole thing doesn't it because of the little it's not grabbing the right color I don't know what's going on there clearly this is green right there we go I don't know what I was doing there we go that's fine I work just grab a rock large tall I know that I'm going to put it right here and in front of that we're going to place a sign just a blank sign it comes with it and we can use this as an interaction object that's good and I'll add a fern with some grass all right beautiful right beautiful grab a treasure chest and I'm going to place it in this cave around you know make it looks fine I don't like to link the angle of the lighting that I have here I'm going to grab this because we're creating shadow what we should not be there we go like that bit more you can use this there we go looks better and then I want to grab my lamppost which this is why you like some organization in this I'm grab blent post and in sign of lamppost what I'm going to do is I'm going to add a light I'm going to add a spotlight want to raise it up here push it over what's the orientation we got going on okay so it's going to be rotated just like that we're going to rotate on the X 90 degrees and we're going to put it let's put it at zero zero zero to start out with just like that I'm going to bring it out and bring it up put it right below this light we're not gonna put it in it because we don't want to disable the shadows for this match so we're going to the right below it for now and then I'm just going to a spot angle a bit on it just like that and make the light color just like that you're bringing out a little bit okie-dokie it looks fine and then I would like to see let's grab these crystals because a bit more glowy there and also what I'd like to do is I'm going to go in here and I want to add just a light let's add a point light right in here just in this area to create a bit of the light like it's shining off of these crystals and we can say yeah shadows are fine it's interesting look okay looks fine what I would like to do now Vlad you're tweaking bunch of tweaking I'm gonna just load with that and then grab this and lower it a bit just to give it a looks fun and I want to say we are done with the environment for now I'm sure most of that I cut out or fast forward it because that was quite boring I'm sure and quickly I would like to just oh goodness that right there is the intensity of of something like that looks pretty good and there's the environment going to create an empty real quick call it lighting this is going to be environmental lighting not anything inside of an object itself just we need to put that in okay looks good looks good and I want to create an empty for the player quit doing that please it's going to call it player and within play we're going to create a cube and I want to call it player model or something whatever it will be and player took on a good rotation we got too much bloom ah it's fine it'll work I never claimed to be an artist okay so it's going to be a player I'm going to materials create a new material from player material it's going to drop it on the player model and we're going to make him see oh just a blue color and that's fine it's fine and that will be all we need to do for that and now the fun stuff want to create a scripts folder go to folder name it scripts and the first thing I want to create I want to create the system that we use to detect interactions in the world so if I'm going to click on something I want to know where I'm clicking in the world what I'm clicking on and they want to do based on what I'm clicking on so I'm going to go to a scripts folder create a new script file c-sharp obviously I'm going to call this world the group's world interaction and world interaction is going to handle sending out the raycast from a mouse from the camera intersecting in the world somewhere figuring out what it hit and then telling something else to handle it depending on what a hit so open this up in Visual Studio and get started alright now we are in world interaction I want to set up first of all the method that's going to handle checking looking on tuck checking what we're interacting with it's going to handle grabbing the camera sitting on array and doing something with information we get back and then also in my update method we're going to check for mouse input in this game we're just going to be using the left mouse button for the only input but if you're using out the input manager or something make sure you set it up to work with your input system but for this we're just going to be using the simple input get mouse button 0 we will be using get mouse button down and so we're sitting on a ray but we're also going to have some UI elements right and we want to be able to click on the UI in the game click on a button click on an item in the game without it's sending array to the world and interacting with something in the background it's really annoying right so if I'm trying to look at my inventory and I'm scrolling through the list of items and I click on a litem click on an item it also like making my character walk to where if I clicked in the world behind it so we don't want to do that we also want to check if get mouse button down 0 which is less mouth left mouse button and also if not we're gonna go through the Unity engine real quick down event systems go to the via systems namespace grab event system the class and then inside of event system we want current which is the current instance of the event system that we're using in our game and then the method we're looking for is pointer over game object and that's going to see that if we are hovering over the UI or not if we are not it's fine it's said okay you're not trying to click on the UI so do whatever you're doing but if we are clicking on a button on the UI we're just going to stop right there and it's never going to send an array into the world which exactly what we want and then I want to call get interaction get interaction done so now I'll have to do is handle our logic inside of get interaction and we're good to go the first thing I want to do is I want to create array that sent out from the mouse point when we click on in our screen space right so within our viewport I'm going to click over here somewhere I want to take that coordinate of the mouse send out array into the world and intersect with an object in the world to do that I want to grab first set up in our array and I want to call it I keep saying an array set up a ray it's hard to see without saying array set up ray with I'm going to call it inner act interaction Ray's die and we're going to set up the Ray vats camera domain so go to the camera class grab the main property which will give us a reference to the camera in game that is tagged with main camera and I'm going to use the method screen point to Ray it's going to take the screen point that we pass it in this case the mouse position cast a ray from it in a forward direction of the camera and it's going to be input done Mouse position and that's all we need to set up the array right wait I said the raycast still but the Rays there and I want a way to store the information that we get back we have an arrow up here what is this oh sorry this is actually a method and I was treating it like it wasn't so on a way to store the information that we get back so we can look and see what we got right and to do that this is just typical ray cast stuff on the raycast hit which is something we can out output the information from our ray cast - so ray cast hit won't call it interaction interaction info and now it's set up our ray cast so it's going to be a true or false just a boolean so go into an if and we're going to set up the raycast with physics dot ray cast and we're going to the physics class grabbing the raycast method and this is going to handle sitting out the Ray that we already set up here it's it took this ray we're going to send it into the raycast there it's going to handle the information and then give us the information back that it finds so I want to pass it I'm going to pass it to my interaction ray as the first parameter the second parameter want to pass it my ray cast hit object so I'm going to output the information to this so out and then interaction info so take the information that got and send it out to the interaction info object which is a ray cast hit object and then it wants to know how far should the ray go and we wanted to go until it hit something so what I'm going to do is just make sure it never stops until it hits something so I'm going to go through the math F class which is the math class that comes unity not the math class of net and then grab infinity which is just what it sounds like and now oops inside of the raycast I first want to set up a game object so game object type and I'm going to call it interacted object this is going to store the object that we hit so we're going to hit an object with a ray cast and we're going to grab that object and store it in interacted object so we can do something with it later on so equal to interaction info which is what we called our ray cast hit interaction info dot Collider so I'm gonna go through that it now has information about the object to hit so we can use that go to the component of Collider which is the same as get component Collider but we're just using the shorthand Collider and then I want to grab the another shorthand for game object so we won't be game object of the collider that our array hit and that's all we have there so now interacted object is the object that we hit if we hit something if we didn't then it doesn't equal to anything and it's just done okay so now we have a couple of options we have an object that we hit but we want to know what we hit and we need to know what to do with what we hit and a way we can check is we can tag things in the game with certain attributes so if we were to we want to know if it's an interactive object and if it is we can tag all interactable objects with interactable object that way we can check and see is this an interactive object because if it is do something different with it than we would if it was not if it's not say it's just the ground right all we want to do is walk to wherever we clicked but if it's not the ground we want to do something with it walk up to it and talk to it woke up to an attack it welcome to it and pick it up whatever it is so we want to check see so I'm going to do conditional I'm going to say if the interacted object that we just got if the tag on that object and we'll go over that in a second but the tag on that object is equal to and I can just set it to anything that's a string it's a interacted object so if it is in fact an interactive object it was it interacted I'm an interact to Bowl then we want to do something with that object we don't have anything set up to do anything with yet so we're just going to keep it like that and say we're going to log out something interactable interactive if it's not interactive object we want to do something else with it so it's going to do a simple else and if it's not we want this move our player right so now we're at the point where we want to set up player movement and the movement in our game is gonna be based on where we click the mouse is gonna walk there but what if he has to walk around the wall what if he has to walk through a door we want to make sure that he doesn't walk through the wall we want to make sure that he can walk around the wall so I had to set a path finding and in unity 5 the navmesh that comes with unity is no longer a pro feature only so we can work with that directly in unity and it's very very simple so we're going to go back to unity and we're going to set this up so they can start pathing which is a lot of fun first of all I'm going to save my scene before something happens and I lose everything it's going to call it test just like that and what we have to do first is we have to tell the pathing engine that the objects that we're feeding it are static which means it's they're not going to move during gameplay so it knows okay these objects are here I can be sure they'll be here later on too that way it doesn't have any surprises later on it's going to build the navmesh around these objects so if they move in the game we'll have to update a navmesh which is for a different tutorial so for this we're going to make sure everything's static that we want the player to go to walk on and around and that's all we have to worry about so I'm going to grab I guess it be everything in my environment really yeah it would be so what I want to do first I'm going to go to window go to navigation it's going to open it up over here for me at least and I want to go to mesh renderers it's going to just show me all the mesh renders which all these blue ones I know are prefabs which means I placed them from my inspector so I know all of these are going to be things too to walk on or around which is fine and I also won't be ground I'm going to select all those and I can turn this on by saying navigation static now all these are navigation statics which means they cannot move in the game or to mess up the navigation and they're all set to walkable which obviously that's not what we want right so what I want to do is want to grab the ground first of all and say ok the ground is walkable I know that but I know that's not walkable these aren't walkable that's walkable no it's not these aren't walkable and you'd probably do this as you're building the game out as you're building a level out but for me obviously I didn't care about the lid just the base and the plant could be walkable it's fine she wants to be and that these can be walkable or just flowers we have everything selected and I want to turn this to not walkable which means these will be cut out in the navmesh that it generates and that's exactly what I want so with that setup I'm going to go to bake I'm going to leave the settings as they are because it should work fine with our mat and I'm gonna click bake and depending on the size of your mat this will take a while but notice for me it was pretty quick okay so what I see here we go to advanced I'm going to do a manual node size and our voxel size and what it says is to keep it between 2 and 4 voxels for agent radius this is Jess Chan we're at 3 so far it's what I'm going to do is I'm just going to turn this down a bit which is going to up my voxels so put that point 15 but there's a 3 point 3 3 if I bake with those settings so what happens all right so nothing changed I also want to lower the max slope because we don't walk up the 45-degree angle bake that I'm not sure what its cutting out there I mean honestly that won't be noticeable in our game to be walking around you're not going to see that he's not going to go to walk in that area there but I'm just curious as to what's happening just make this ridiculous real quick and make it a low amount of voxels hmm but the mesh looks pretty good with than that notice he can't walk on the mountain they can walk up to a certain point but in the mountain he can't actually get on the sides of it and if you don't if you don't know exactly what a navmesh is the blue hair you're seeing is the navmesh and that's where nav agents in the pathing system it's a word they're allowed to path to so it's exactly 1 so if I click somewhere on the blue area he can walk there if I click somewhere not on the blue area he can't walk there and these are areas that he can path around to get to other places just to show you real quick we're going to set that up I want to grab go back into my inspector let's uh go back to all I want to go to my player on player I'm going to add a nav mesh agent ok nav mesh agent remove the box Collider from my player model don't need that so a nav mesh agent first of all is set up the collider on the agent let's make it one and was it negative 0.5 I'm sorry point fun apply five point five and that's going to be our Collider and all of this is fine for now these are the settings for the ADA to walk on his path the speedy walks the speed turns around how quickly it gets to his max speed and how far away from his destination he stops these are all things we'll be messing with in our controller so don't worry too much about that right now so now that our player has the nav agent on him world interaction is also going to be on our player so what I'm going to do is I'm just going to set up a nav mesh agent that's the type of object I'm going to call it player agent and in start we're going to say player agent is equal to get component nav mesh agent and it's going to grab the component on our player nav mesh agent and if you're confused by this this tutorial series is putting a bit to be too advanced for you so check us from my other stuff on the channel or any other things on YouTube there's tons of tutorials out there so with player agent with that reference we have if it is not interactable object what I'm going to do is I'm going to say player agent and we can set the destination right so it's going to be the target location for our player to walk and what that's going to do is it's going to generate a path from our player agent to the target location is going to path around the obstacles I can't walk on and it's going to start moving our agent along that path turning it steering it depending on the direction it's going so I'm going to handle that for us and we don't have to do much at all really sunset player destination to the interacted object now interacts on my narco objects going to be interaction info interaction info dot point and that's the point on the object that we clicked it's going to be just a simple x y&z point and so our destination is going to be that point and is going to move his way there so we were to go back into here grab a world interaction going to take that drop it on my player and let's see what happens don't we got an error of course oh right what we're doing is we're checking the event system the current one to see if we're on top of it when we click but we don't have one because they don't have any UI in the game yet so quickly I'm just going to create just for that purpose want to create UI and I want to go down to just canvas and that's going to create an event system for us as you can see there and we don't have to use it for anything our now just so that we don't get that air and when I click play and I click on the ground my player moves to wherever I clicked it's a little slow little sluggy so let's grab my player and I'm going to turn the speed up so like 8:00 and the angular speed the speed which at rotate is important to me because it looks like it's too slow so I'm going to do like five hundred an acceleration is also quite important so I'm do something like 20 see how that is it's not bad okay so the grass has a Collider on it as you can tell from that so it's not I don't need that let's go down to my grass patch square remove the mesh Collider grass patch square grasp inch square and grass patch square that's fine and could play and I can move and look at this I'm gonna click over there he's going to make his way around does it still have a Collider oh did it generate a bump in the navmesh hmm that's interesting it did alright so we can fix that so I'm going to go back into here take this it's walkable well that's fine let's just rebake everything and see if we get rid of that it's going to turn off the navmesh generation for these all together because you can take out some not necessary I just baked that again and that should flatten this out there looks good and we play walk over that everything's fine he goes we're on time to go he goes up the hill on the cave looks good a latte looks really cool I like it and that is our character movement now in the next part we're going to work with our interactions to interact with objects so click the crate something happens have an NPC in the world something happens with that when I click on it maybe the sign maybe the chest and get the idea so it's going to be in the next part this part was kind of long but we covered quite a bit if you like this series so far if you like what we're going with this be sure to let me know in the comments of this video if you have any suggestions that are within scope and imagine a pretty small scope very simple RPG ideas I'd love to hear them guys thank you for watching my name is Austin and I will see you next time
Info
Channel: GameGrind
Views: 395,013
Rating: undefined out of 5
Keywords: Unity rpg tutorial, rpg in unity, unity 5, unity inventory, npc system, dialogue, click to move, arpg, action rpg, unity how to, unity, tutorial, rpg
Id: 36ruPSD7FJk
Channel Id: undefined
Length: 44min 19sec (2659 seconds)
Published: Fri Oct 28 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.