Third Person Game From Scratch with Godot P1 : Character

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

this is dope - looking forward to part 2

👍︎︎ 2 👤︎︎ u/ok_annie 📅︎︎ Dec 22 2020 🗫︎ replies

This is looking really good so far! Thanks for the tutorial.

I think the process mode of the AnimationTree should be set to Physics if you use it in _physics_process, but I'm not 100% sure.

Also in the AnimationTree I think it's more flexible to set your tree root as a BlendTree, because you can create state machines etc. inside it and not the other way around.

👍︎︎ 1 👤︎︎ u/G-Brain 📅︎︎ Dec 22 2020 🗫︎ replies
Captions
so i'm a programmer when i want to relax i usually play video games but also i like to try different things and play around with some softwares and recently i haven't been doing much programming for my game since i've been doing like marketing and release stuff so i figured why not relax a little bit and try to come up with a 3d third person shooter in good old and see what i can make i actually have quite a bit of experience making third person shooters but i've never done it with good old so i figured while i'm learning i might as well share a bit of wisdom with you [Applause] so the first thing i'll do is create a new project in good old and we're going to call it maybe tps youtube and once we have the basic folder structure for google we can go ahead and create my own personal structure of how to i like to organize my file that means having a data folder a scripts folder and a scenes folder and in the data folder i'm going to create a source folder and this is going to be to put all the krita file or the photoshop file or the stuff that is not going to be used inside the game but i want to keep inside the project and i'm going to create a gtd ignore file here to tell dodo that i don't want him to process this folder now i'm not an artist and i'm not an animator and this isn't a blended story also i'm not going to show you how to create animations and models in 3d i'm just going to go to mixamo which is a website where you can download free animations and models for your games and i'm going to download a couple of those for my game now i started with this tpos wide bot as a prototyping model and i downloaded a bunch of animations i wanted a few animations to try to prototype a couple of different interactions between the animations so i went with a walk cycle here i went with a running cycle here an idle loop and then i wanted some one shots that i could blend with everything else so i downloaded this jump animation and this second running jump animation and i put them into my source folder now if you notice some of these animation have a checkbox called in place this is because there's kind of two ways of moving a character with its animation one is moving it in the code and one is something called root motion so when you click in place you'll see that the character has the same animation but he's not moving and when you remove the in place then he's moving that's because the movement is actually baked inside the animation and from all the years i've worked in the game industry we've always used root motion for character movement because this is much easier to make sure that the character is not going to be slipping on the floor and it looks much more anchored inside the world you're making the problem is downloading this animation from miximo the root motion is actually the hips bone and try as i may i never managed to get it to work in godot i tried many things believe me but there is always something off with the animation thankfully i found on itch.io this good old game tools plugin for blender that will not only add the proper root motion that guru needs but it's also going to be able to merge all the animation from different fbx files from mixamo into a single animation player for good old to use which is really a big time saver so the way that works is that you're going to download this plugin and boot up blender delete all the default items and then go into the edit preference and click on the add-ons and if you've downloaded the file on dot io you can just go click install select your file and it should show up in the file as go to game tools make sure it's checked and then if you click can it's going to pop up the property dialog and you're going to have the good old game tools tab here and if you go into character utility armature you can initialize with the characters you downloaded so let's say i load the first t-pause of my character he's gonna show up here in blender and then what you can do is join animations and then go and select all the other animation for your character like the idol the jump the running the running jump and the walking and then click join and after a little bit of time all these guys are going to be loaded inside blender now if you go into the root motion section i'll make that a bit wider you'll see that there's this apply root motion to all that you can check and then if you look it's going to create this root motion bone and it's going to base it on the hips bone and this is already configured for using mix mode setup so you don't need to change anything and you can just click add root motion and once this is done you can go into the export character and you can choose your folder and just give it some name for example ybot and export the character as a gltf file now we can go back into godot and select our project we created before and now we need to create our test scene that we're going to play where our character is going to move so for this we're going to create a new 3d scenes and we're going to call it main and i'm going to save this scene inside my scene folder now we need to create a bit of geometry for our character to interact with so the way i did that is i created an empty spatial node that i called level and inside of this i created a bunch of mesh instance this is nice because you don't really need to model anything i just created these uh cube mesh and i sized them so for example i put the floor as 0.5 height and 100 in by 100 and as you can see i already kind of have a floor now it's nice to have a bit of texture so that you have a better idea of how far your character is moving or quickly your character is moving and all that so to do this i went into again some free texture pack that i found on kenny's website there's this prototype texture pack with a bunch of different colored texture with different grids that you can use and i downloaded this into my data folder inside a texture folder and now that we've downloaded that into our project we can take our mesh instance and in the materials section we can create a new spatial material and in the albedo we're going to load one of the texture i just downloaded let's say for the ground we can go with the dark ground and just put this like this of course now the uvs are mapped to one to one but if you remember our cube we stretched it a hundred unit long so i can just scale this by a hundred unit and so now we have this nice grid pattern that we're going to be able to use as a debug level or what people call a block mesh now of course we want this to be physically interactable so to do this we need to add a static body and the static body needs to have a collision shape so we're going to add a collision shape and this shape again we're going to make it a box and we're going to set this box as the same size as our floor that we just created so 100 like you know 50 like this 50 like this and 0.5 and 50. so now we can see that the collision is fitting our box that we created as the floor now of course it's nice to have other stuff to interact with so you can create just another bunch of cubes with the mesh instance to you know create some interest in your level i mean it doesn't even have to be cube it can be cylinder or prism or whatever so but i'm just going to stick with cubes for now so this will be just like a default cube like this i'm going to again apply some material to it like it doesn't need to be anything pretty it's just to give it a little bit of color and function and now that we have this cube here we are going to add another physic material to it and we can actually just duplicate this to create many different boxes and i'm going to scale them a little bit just to have different size of boxes it doesn't even need to be like scaled uniformly and i can have this be like 100 unit long maybe that's a bit too much like 20 unit long and i can put it a little bit inside the ground to make it a little bit lower and one thing that's nice also is that you could always create a mesh and rotate it a little bit so that it becomes a slope because in this kind of game slopes can often be a source of problem the character is going to slide down a bit or when he falls down some height you want to test the animations so it's a good idea to have a slope so you can test like different you know behavior when you're climbing stairs or stuff like that so now that we have our level it's time to create our player for this we're going to create a new scene again we're going to this time make the root node a kinematic body and we're going to put our bot inside this kinematic body and i want it centered so i'm going to reset its transformation now if you look inside this we have the animation player with all the animation we exported from blender but we are not going to be directly using the animation player because we want to have a little bit more control over how the animations are played so for this we're going to be creating an animation 3 and in the animation 3 it's pretty easy there's a couple of things we have to set up first we have to tell the animation 3 which animation player it's going to be driving so it's going to be driving this animation layer and like i mentioned before we're going to be using root motion so in the root motion section we have to assign the root motion bones that blender added as you can see under the root motion there's the hips from mixamo and this is the one we added from blender now you can go into the tree root and you can add a note state machine and you can add inside the tree all the animations that are from the character actually we don't need the t pause now if you want to test it you can just click on the animation three and make it active and you can click the little play button to see if everything is working fine now one thing to be careful is don't go playing animation in the animation player and in the animation three at the same time because that's going to create some very weird issues if you want to test an animation in the animation player just uncheck the active from the animation tree and for now what we're going to do is set up some transition between these animation so for now i'm not really interested in the jump animation but i want to set up the walking the running and the idle loop and i'm going to rename them so it's a little bit easier we're going to call it idle running and walking and to set up the transition you click the little transition here and you can just drag and drop between the different states and in our case we want all transition between all animation there's no like going to walking before going to running or something so we just want transition everywhere and if you click on a transition you can set up a couple of different properties but for now the only thing we really want is to add some x-fade time which is going to be a time of transition between the two animation so that godot can blend these animation together for a little bit if you had perfectly synced animation between each other you could probably do with instant transition maybe select the sync here but since i downloaded from miximo a bunch of different animation and i'm not quite sure how it works i'm just going to blend and it's going to look i think pretty alright you have to do this for all the transition that we just created now you have to be careful because this transition mean that even when you go back to the idle state the character is going to be moving a little bit while it's transitioning and that might be fine for some but it might also be an issue if you want really snappy controls that's something to see for later now of course this is a kinematic buddy and it's complaining that it doesn't have any shape or collision shape so we're going to again create a collision shape here for the rigid body and we're going to make it a capsule and we're going to fit it to the character's body by rotating it a little bit and then playing with the size i mean it doesn't really matter it just needs to fit approximately i think it's not so important for now maybe eventually you'll want like a more complex hitbox if you're doing a shooter or something but for now the capsule for movement is going to be plenty enough if you want to reset it you can just go into the animation player and select the first frame so this way your character is going to be centered where it should be and you can see it fits pretty well so we're going to save this in our scenes as the player and we can go back and add the player into our level now we can go back into our player and actually one thing i forgot is to set the idle animation as the starting point for the state machine so that the character is always going to start in the idle state now the next thing we need to do is add a script to the kinematic body to make our player actually move so we're going to save this as player control and the only method we really need right now is the physics process because it's a kinematic body it's really important that we move the character in the physics process another thing we're going to need is a reference to the animation tree so it can switch the animation state of the player so we're going to export a notepad here that we're going to call the animation tree and we're going to have an unready var that's going to be the lm3 and technically we should be able to assign the animation 3 to r and m3 here and we can go here for now all i really want to do is make sure that when i hit the key the animation is going to be able to travel from one state to the other so i'm not going to get into all the control schemes for now that's going to be for another video because otherwise this video would be way too long so all i'm going to do for now is add an if input that is action pressed and for now we're just going to put whatever say ui select which is going to be the space bar and then we're going to say if you look in the animation 3 here you're going to have the parameter option and these are created dynamically based on what you have in there and if you look it has this playback and if you hover over it it's going to tell you the path to this parameter so in this case it's parameters playback so what you can do is just do an m3 and do parameters slash playback and this is going to give you access to the uh state machine that we have so we can just do travel and go to the running animation and if no key is pressed then we can just go back to the idle animation and with just that if we go back to our main scene and maybe set up some static camera just so we can see something so i'm just going to position the camera a little bit so we can see the player and if i hit play and i hit space then the character starts running and if i release then the character stops running though he's running in place and he's not very physical yet so let's fix that if we go back into the script if you remember i talk about the root motion the thing is is godo is going to take the information in the root motion bone and it's going to keep it and not apply it to the model so it's our responsibility to apply the root motion to whatever it is we want to move because maybe we don't want to move just the model like in our case we want to also move the collision from the kinematic body so to do this we need to go get the root motion transform and we're going to do this by going root motion equal and m3 that get root motion transform now a transform has a translation and a rotation but we're not really interested in the rotation we really just want the translation so to apply the translation we're going to get it as a velocity from the root motion transform and then we can pass it to the move and slide method that's going to move our character rigid body now if i do that and i test in the main scene now when i hit play the character should move forward of course if i move him up a little bit and i hit play again you're gonna notice that he's kind of floating in the air that's because we are responsible also for applying the gravity now the gravity is an acceleration and what we're passing to move in slide is actually a velocity which means we're going to have to keep the gravity acceleration from one frame to the other so we're going to add a new variable called gravity and we're going to initialize it to zero now i don't want to keep adding the gravity all the time because when the character is on the ground actually the gravity should just return zero so what i'm going to do is that the kinematic buddy in good o already has a very useful function to test if something is on the floor so i can do if is on floor gravity equal vector three that zero else we're going to add a bit of gravity and of course this is a vector 3 because you could have gravity in a way you want but in our case it's just going to be in the y direction and we're just going to use standard gravity like this and in the end we're going to add our gravity to our velocity and just by doing this normally when we go back in our character he should be falling on the floor and actually if i move my little slope turn it around so that's working pretty well so with just this we already have a basic animation system working we know how to import new animations set up the state machine and everything and we have some physics going for our level now the next step is going to set up a camera structure that will allow us after that to follow the character around and making turn and jump but this is going to be for the next video so see you all in my next video bye
Info
Channel: Ombarus
Views: 26,779
Rating: undefined out of 5
Keywords: Guillaume Bouvier, Ombarus, GameDev, Programming, Coding, Software Engineering, Third Person Game, TPS, Game Tutorial, 3D Game Tutorial, Godot Engine, 3D Game in Godot, How to make a game, Third Person Shooter, 3rd Person Shooter, 3rd Person Game, Build a Game, FPS, Character Controls Camera, Three C
Id: EmQBLxxPV3E
Channel Id: undefined
Length: 21min 41sec (1301 seconds)
Published: Mon Dec 21 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.