Let's Make a 2D Character Creator in Godot 4 & GDScript | Part 3

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello everyone and welcome back to our character creator Series in gdau 4 in the previous part we created our main scene and we imported our assets and project settings now in this video we will create the base for our player which is the actual character that we will move around the scene so let's open up our project and at the top let's create a new scene this new scene should have a character body Tod node as its root node this node will allow our body to execute physics so that it can move around the map rename this note to player and save the scene to your scenes folder attach a script to the root node of the scene and save this script in your scripts folder you'll see that we have a little warning sign next to our character body 2D node this is because we need to add a collision shape Tod know to our scene we'll give this Collision shape a simple circle shaped Collision which will allow us to interact with items and be blocked by other physics bodies and it will take the yellow warning away to the scene we'll also add a camera 2D node we are going to add a camera to our scene so that we can focus on and follow our player around we'll change the zoom value in the inspector panel to a higher value such as three because we want to be pretty close to our player now we'll have to create the skeleton for our player our skeleton will comprise of the different body parts of our player so our body our hair our outfit and our accessory each of these parts should be separate from one another so that we can easily manipulate its appearance visibility and color this means that our player can have different to know hair outfits and accessories let's add another node 2D node to our scene this node 2D node will contain and organize all of our skeleton parts so we'll also rename this node to node to skeleton now for each part in our skeleton so our body our hair our outfit and our accessories we'll add a Sprite 2D node to our created skeleton we're using a static Sprite 2D node because we want to change its texture property in our character creator to reflect the features that we want we'll then later on animate these individual Sprite 2D nodes with an animation player node which will allow us to animate the different parts of our body irregardless of the texture that is assigned to our Sprite Tod node so you'll see how that works in in a bit I don't want to confuse you because I know I am um so for now let's just add our Sprite 2D notes and you'll see how this all works in the future if you have more Sprite sheets say I shoes shirts and pants you will add these features as separate Sprite 2D nodes we only have Sprite sheets for our players's body hair outfit and accessories so that's why we only have four Sprite DD noes but if you have Sprite sheets that have a lot more features for a whole body you will add them here now let's rename each of these parts to reflect the type of feature that this Sprite 2D node will change in our player also add a label note to your skeleton now this label note is for testing only since we are also going to give our player a name and we'll use this label to see whether or not our player's name is actually setting and being changed also rename this label note to name now to each Sprite 2D node we'll need to add a default Sprite sheet to each of these Sprite 2D noes texture properties in the inspector panel so that we can crop out the individual frames of our Sprite sheet this will help us to not only focus on an individual frame to see if our Sprite is displaying our set option AKA our chosen body hair outfit and accessory but it will also help us later on when we want to create our animations for our player if you look at your assets folder you'll see that there are a few spreadsheets for each of our skeleton parts there is only one for our body spreite sheet because I only had one body in the free asset pack but if you have different bodies say like a female body we would add it here let's open up two spread sheets for our accessories you will see here that you have two different hats now I want you to take note of the frame count horizontally and vertically on each of these spreadsheets on each of these spreadsheets you will see that you have exactly eight frames horizontally and vertically you will also see that both of these Sprite sheets are the same size which is 32x 32 let's see if this is the same for our outfits let's open up two random outfit spreadsheets and you will notice the same thing now this is important because later on when we add animations we'll need a consistent grid that will play the animation regardless of which specific feature is chosen because all features follow the same layout in their Sprite sheets so if you are making your own system later on with your own Sprite sheets make sure that all of your Sprite sheets follow the same layout and all of them have the exact same size if you can't have for example your body and accessory spreadsheets to have the same layout make sure that at least all of your accessory spreadsheets are the same all spreadsheets of the same feature has to be the same that is the rule so let's get back to adding a default spreadsheet to each of our skeleton parts and then cropping them out select your body node and drag your only body spreadsheet into the texture property for this spreadsheet we counted eight frames horizontally and vertically so we'll crop out our frames with these values now select your hair node and drag the first hairs spread sheet into the texture property also crop it out at 8 frames because it has eight frames horizontally and vertically select your outfit node and do the same do the same for your access node and here we have the base set up for a player skeleton we might also want to add some text to our name and move our label above our player's head okay so let's add some movement code to our player now we're not going to animate our player yet because we still need to create our character creator which will add features to our player so for now we're just going to add some basic movement to our players so that we can move them left right up and down open up your player script and let's clear the existing code we'll have to create two new variables that will store our player direction and speed now in our physics process function we can update this last Direction variable based on our movement input this physics process function is called every physics frame which is separate from the rendering frames so it's typically where you handle physics related updates within this function we will create a new variable which will store our Direction as a vector 2 object this direction will change on the X and Y AIS depending on our input so if we press left the x-axis value will go below zero if we go right the x-axis value will go above zero if we press up and down the Y AIS value will also change respectively if you're unsure the UI left UI right UI up and UI down are input sets already defined by gdau in our project settings it adds access inputs to our up down left and right um arrow keys on our keyboard we'll then use this direction to set our player's velocity which will move the player in that direction at the speed that we set for our player finally to move our player we'll need to call the move and slide method to actually execute the physics on our body this will move our player in the determined velocity based on our input to see if our player is moving around the screen we'll have to temp temporarily disable our camera so make sure that your camera is disabled in the inspector panel back in our main scene let's instance our player scene make sure to drag your player to the middle of the Border in your screen so that we can actually see the player if you're onun your C now your player should move in the Press Direction and that is it for this video in the next part we will create our Global script which will sore all of our feature values that's it for me thank you so much for watching and I hope to see you in the next [Music] [Applause] [Music] one [Music] he
Info
Channel: Oops I Dev'd
Views: 2,551
Rating: undefined out of 5
Keywords: godot 4, godot, 2d games, game dev, tutorial
Id: Si6FBHRn7Vs
Channel Id: undefined
Length: 15min 7sec (907 seconds)
Published: Thu Feb 15 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.