Make an Action RPG in Godot 3.2 (P12 | Roll State)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
good morning afternoon or evening wherever and whenever you are my name is Benjamin and welcome to part 12 for our Godot action RPG series in this video we're going to be adding in our role state in the previous video we had our attacking in and but now I want to be able to have some nice movement with rolling around in the room before we start adding in our enemies so we're going to come into our players scene and we're going to come into our animation player and we're going to start adding some new animations because we need all of our animations for rolling so we're gonna do roll let's see we're going to do roll down new animation roll down and this is going to be 0.5 long here wait yeah that's right I assumed the wrong way there we go and we're gonna come into our sprite we're gonna flip through our frames here until we get to roll here we go find roll down okay here's the first frame of roll down right here key this frame come to our next frame key key key and key there we go now let's create we're gonna actually save here we're gonna create a new function and we'll call it roll animation finished here we go we'll say state equals move save and at the end of our animation here we're gonna add a new track call method track player insert a key by right-clicking insert key and then search for role animation finished and save there we go we don't want this attack to loop and well we do want it to loop for now because we need to wheat what we'll need to set it up in our animation tree so let's add in roll left new roll left 0.5 we'll come back here until we find the first frame of roll left which is this one frame 50 there we go add a new track call method track on the player insert a key role animation finished save now we're gonna do roll right [Music] here we go 40 create oops let's move this frame all the way back to the start if you accidentally key it in the wrong spot you can move it make sure we turn on that there so we've got roll right or looping I should say I'll come to this frame key uh-oh I accidentally keyed on the wrong frame there okay key key key key key okay so you should have it start here on frame 40 and then go to frame 44 and the very last frame here we're going to add a new method track player of course right click insert key roll animation finished save want to make sure that roll left is set to looping as well and let's see the only one we haven't done yet is roll up right come in here find roll up here's the first frame of roll-up here's the second one Kiki Kiki and then you need to add a new track call method track player insert key roll animation finished okay there we go so we should have all of our set this to loop now we can go into our animation tree here and we need another state inside of our animation tree and we're going to have this connect to idle as well so we'll create a new blend space 2d we'll call this role and we'll connect our idle to this so we'll have our click on transitions will connect to idle and then back here so we've got transitions between the two and we can come in to select our role and edit it and we'll make sure to set the blend to the little dots let's see it's inactive so I want to set our animation tree to be active so that we can see these updating will come to add some points we'll add one here add animation role left add one before we add one up here we want to change this to point one this to negative one point one then we can add it up here add animation role down add animation role right and then down here add animation role up and then we'll switch back to this and we should we're still we're not seeing it update here oh yeah we got to make sure and play it so let's play our role and come in here and you can see we can now roll in all of the directions properly perfect so come back and press the little auto thing here to play idle again and turn off our animation tree so it's no longer active because we activate it in code come back into the animation player and make sure to turn off of turn off loop on all of these roll animations so they no longer loop because we don't need them to and then we can set our animation back to our idle state here okay so now we've set up our animation tree we need to come in to code and make sure in set the blend position on our rolls so we're going to do it in the same spot that we do everything else here call this role blend position okay inside of our move state now we already have our roll state here but let's create a function for it and we'll create it in between here and between our move function and our attack function roll state it'll take Delta and then we'll do do pass for now now we need to transition to this just like we have a transition to attack so we'll say if input dot well let's create an action for this inside of our input map so come into project project settings input map will create a new action called role and we can add a key here so I'm going to do the K key and then let's do the Zeki and I'm not sure I actually like space for our attack anymore I'm going to take that off and I'm gonna do X so if you're using the arrow keys then X will be attack and Z will be roll but if you're using WASD then J will be attack and K will be roll close that and then we can have our transition here we'll say if input is action just pressed roll state equals roll so we're changing to our roll state we need to make sure and call our new roll state function so roll state Delta okay and this will properly set our state the problem here is that once again our state doesn't actually do anything so if we switch to our roll state we just kind of get stuck there animating can't do anything about it so let's actually make our roll state function do some stuff let's check her output down and get rid of it here and what well the first thing we'll do is set well we're going to need a roll vector variable so we'll come up here we'll say var roll vector now this variable we need to store our roll vector inside of our our move state so basically what we're going to do this will allow us to roll in all of the directions that we can move in it will remember the direction that we're moving in basically our input vector and it will allow us to roll in that direction but it only remembers it it only sets that roll vector while we're actually attempting to move that way you can't roll in place so if your input vector is 0 then it won't update this roll vector so we actually don't want our roll vector to start out at 0 we want it to start out facing the direction that we're facing that the player sprite is facing and currently we're facing down so we're gonna set the roll vector 2 down vector 2 down okay and then inside of our input map here we're going to set our roll vector so we'll say roll vector equals input vector but we only do this if we're not 0 right because if our input vector is 0 then if we press the roll key and this will be set to 0 and our character won't roll they'll roll in place which is what we want to avoid but if we if we update this only when we're moving then even if we stop moving the last time that this gets set will be the direction we are moving in before we stopped so then we'll remember the direction we were moving in and roll in that direction or essentially the direction that our character is facing and that's what we want here so once we've done that we can come into our roll state and we can say velocity equals max let's see where do we set our max max speed velocity equals roll vector x max speed and this this roll doesn't have any sort of a this rule doesn't have any sort of a acceleration to it just instantly reaches the max speed the minute you press the roll button now this is our normal max speed and we want our roll to be actually a little bit faster so we're gonna do max speed times 1.5 the other thing we could do actually is to create a roll speed constant up here and I actually like that idea more so we'll create a roll speed and we'll set this equal to 80 plus 40 is 120 so maybe 125 will be a little bit faster than in my other one and then we can come down here and multiply by roll speed roll speed I think that's a better plan and we need to make sure we update our role animation update to our role animation in here we'll say let's see where here it is we'll say animation state dot travel role and we should be able to save and this should work now oh no we forgot one last thing the problem now why are we rolling in place and then we have some momentum afterwards well it's because we're not actually calling move so we have our velocity equals move and slide I actually want to create a function for this where we update this so we'll create a new little function down here we'll put this between our attack state function our roll animation call it function move and this will take does this need Delta I don't think it needs Delta it doesn't need anything really so we can just say copy this into here so velocity equals move and slide velocity and then up here in our move state we can just call move and then inside of our roll state we can also call move and that will allow us to easily call that inside of any state and [Music] trying to decide I don't think I like the sliding [Music] yeah I don't like the sliding it's too much - to have it slide that much so we can we can set it to not slide at the end of the animation we get inside of our role animation finished here we could set velocity equal to zero and that should fix the sliding I think but that's a personal preference maybe you like this lighting mm-hmm it is it does feel pretty jarring I wonder if we just did I wonder if we just have our velocity and we got to fix that because we apparently face left not down having the velocity feels interesting - I don't know I'm not sure what the best solution here is in my reference project we don't have any sliding and I I don't I've definitely changed some things along the way so I'm not necessarily sure what exactly was different oh that's gonna kill me we got to make sure and set our roll vector to left here left there we go so yeah I'm not sure exactly what was different maybe it is just the actual speed that I set it to like maybe I need to be setting my roll speed to not quite as fast so you know 120 that seems like a very minor difference maybe my frictions lower that could be it - I've got a much lower friction I don't know maybe this lighting isn't too bad it just feels like we travel really far in our role you're committing to a lot of movement maybe if you try and turn around you're kind of slide it's a big commitment I don't know it feels kind of good actually the more the more I get used to it was jarring at first because I wasn't used to it but I think I liked it and I still think if you wanted to reduce it you could have it reduced here in the role animation finished just set your velocity is something like velocity equals velocity times 0.3 or something and that would that would give you well that's too jarring too let's try point eight so then our velocities 80% of our yeah we get a little bit of a slide there but not too much of one so you guys can decide that kind of what you want this number to be right here and maybe you just set velocity velocity equals yeah this is this could work here I'm gonna just leave the sliding in I think well I don't know I kind of like this in-between here or we don't slide a ton but we do slide a little but you can see we can roll in all eight directions and it feels really nice to be able to roll so this video was sponsored by my Kickstarter backers for the one bit kit of course I'll put a link to that in the description thank you all so much for for your support I hope you enjoyed this video and learn something from it if you did be sure to give it a like and a thumbs up subscribe to my channel I'm gonna be doing a lot more videos like this in the next video we will be working on starting our enemy we're getting close we're getting close I think this series will end up being about 20 to 25 videos I'm I'm not 100% short cuz sometimes videos take longer or shorter than I expect and I end up doing more or less so we'll see how things go moving forward but I'm excited to continue working on this series with you guys and I will talk to you all later
Info
Channel: HeartBeast
Views: 54,490
Rating: undefined out of 5
Keywords: Godot Engine, Godot 3.2, Godot 3, Tutorial, Series, Action RPG, RPG, Pixel Art Game, Indie Game, Game Development, Learn gamedev, Gamedev
Id: GWBt1LV9An0
Channel Id: undefined
Length: 19min 31sec (1171 seconds)
Published: Mon Apr 06 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.