INTEGRATION 01 - Making an RPG in Unity (E03)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone in this video we're going to be bringing the player model into the unity project and setting up the animations so I'll start by creating a new folder called characters and if you've been following along with the graphic side of things then you can just drag the player blend file in here otherwise you can get the player package and there'll be more information about that in the description and just import it and we should all be at the same place so with the player object selected I'll now head over to the rig panel and I'm going to change the animation type from generic to humanoid and this is just going to give us access to some cool things like animation retargeting and uh the mechm ik system which will double with uh probably a little bit later in the series so for now let's just apply this and go into the configuration window if I zoom in on the player here you can see that it's tried to enforce a t pose but the legs are sort of halfway through a walk animation so I'm going to go into the pose drop down here and just ask it to first of all sample the bind pose and now he's lying face down I think that's just because of the difference between the blender and unity coordinate systems but then we can say enforce T pose and we've now got this nice standard T pose uh without any funny business going on with the legs so we'll apply that and once it's finished processing we can press done and then head over to the animations panel so in here I just want to go through each of these clips and enable Loop time so that the clips will actually uh repeat so I'll do that for the run and for the walk and then coming down to the bottom here I'll open up the motion field and just set the root motion node to the root transform and press apply okay so once that's done we can go to the hierarchy and I'm just going to select the Graphics object here so this is obviously just a placeholder we'll be deleting that and replacing it with our player model so I'll just make that a child of the player object Let Me Maybe rename this to player graphic so it's just clear what the differenes between these two and then to set up the animations we're going to need an animator controller so I'll right click here in the project window create animator controller and I'll call this something like player animator okay going onto the player graphic we can drag the player animator into the controller slot of the animator component and I'm also going to turn off apply root motion since all of the motion in this project is driven by the scripts and not by the animations all right we can then double click on the player animator to open up the animator window and I'm going to right click in here create new blend tree and I'll call this blend tree locomotion I'll then double click on that to open it up and I'm going to add three motion fields to this little motion box and the first one will contain the idle motion then the second will be the walk and the third will be the run now when we created this blend tree it made this default blend parameter for us so that we can blend between the different motions just by changing the value from 0 to one I'd like to give that a more descriptive name though so I'll head over to the parameters uh panel here and just double click on the parameter and call this speed percent now you can see that I've used the same naming convention that I would for a variable in one of the scripts and you don't need to do this it's just since we will be referring to these parameters by name from the scripts I think it makes sense to stick to a naming convention that you're used to all right so we'll now need a script to actually drive the value of this parameter so let's go into the scripts folder and create a new cop script called character animator okay I'm going to apply that to the top level uh player object so let me just slot that in at the bottom here and I'll double click on it to open it up up at the top we're going to need a reference to the animator component I'll just call that animator and I also want a reference to the nav mesh agent since from that we can get the current speed of the character now to get access to that we need to say using the unity engine Ai namespace and we'll then be able to come down here and create our nav mesh agent variable which I'll call agent now we'll want to assign both of these in the start method so the nav mesh agent component is sitting on the same game object as this character animator script so we can simply say agent is equal to get component of type nav mesh agent while the animator component is on the graphics object which remember is a child of the player object so we'll have to say animator is equal to get component in Children of type animator and that will just search through all of the child objects for one containing the animator component okay so now that we've assigned both of those in the update method we can create a float speed percent and this should be equal to the agent's current speed divided by its maximum possible speed that will give us a value between 0 and one so to get its current speed we have to get its velocity which remember is a vector and to get the speed from that we just take the magnitude of that Vector all right we can divide that then by the agent's maximum speed which is stored in agent. speeed now to actually uh set our speed percent parameter on the animator we'll say animator do set flat and we have to uh call the parameter by name so in quotation marks we call speed percent and this is where we have to write the name exactly as we wrote it in the animation window and we can then pass in our speed percent value now it might be nice to smooth this out a little bit and we can do that by adding in a a third parameter here a damp time so I'll set this to about 0.1 and that just means it will take roughly a tenth of a second to smooth between any two given values uh if we Supply this damp time we also need to tell it what the current Delta time is so we can pass in time. Delta time now perhaps it would be better to make this a variable uh just some up at the top of the class so that it's easy to find and modify if we want to change its value so I'll create a constant float called The Locomotion animation smooth time set that equal to 0.1 and I'll copy and paste that in here okay we can then save that and go into unity and I'll go into scene view here and let's see if this is working so I'll press play and let me just click somewhere and he seems to be running there very enthusiastically and when he sort of starts to come to a halt should see that it goes into the walk animation for a moment there as he's slowing down okay so that is everything for this first integration episode we'll be doing some more in-depth stuff next time so until then cheers
Info
Channel: Sebastian Lague
Views: 343,930
Rating: undefined out of 5
Keywords: RPG, role-playing game, Unity, gamedev, mecanim, humanoid rig, animation
Id: COckHIIO8vk
Channel Id: undefined
Length: 7min 54sec (474 seconds)
Published: Wed Aug 09 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.