2D Godot 4.1 RPG - 5 - Adding a jump mechanic

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we're going to make a jump mechanic enough to the RPG Series so this is a video that I'm excited to do because like there's not much video about that I don't think I've ever seen a video made on that topic so I'm very happy to show you how I do I don't know if it's the ultimate way to do it but me personally it's the way that works very fine for me so anyway if you don't have the asset you can check in the description I have put the link to my hio and you can get them so anyway let's get started so now we're going to continue and this time we're going to configure the jump so for configuring the jump what we need to do is we need basically do the same thing that we have done for this world uh we need to create here in the physic process Delta we need to create a new player State and this time is going to be player underscore state DOT jump and we're gonna jump and we're gonna set it to be jump function we need to create that function now so I'm just going to come here I'm going to say thank jump and then I'm just going to pass fall now and basically we need to do the exact same thing that we have done with our swirl so we need to create an input so we go to project project setting and here I'm gonna create a new action and I'm going to cut it jump and I'm gonna add it and what I'm going to do now is that a jump I'm gonna just click on plus and I'm gonna tap a key so for me it's gonna be I think I'm gonna put it on C uh and so I'm going to click on OK and then I have still my controller connected so I'm gonna click on the plus and I'm gonna just tap on I think X will be good so X voila and so now I can just close it okay and I have my jump uh my jump input right there so that's good so now here in my uh move function I'm gonna just click here I'm gonna make some space and I'm gonna do if input dot is action just press it's going to be Jump Then I'm gonna change the current state current state current state account type uh it will be equal to player state DOT jump and so then here in Jump what I need to do is I need to trigger the anime State travel jump so for that I need to copy that and I'm going to come here and I'm just gonna pass it and I'm gonna replace the work by jump and normally there was a jump with a capital uh J if I remember right so let me see my in my uh animation tree so the jump is there so okay that's perfect so now in the jump we need to do the exact same thing that we have done in this world as well which is we need to reset in the animation player we need to reset at the end of the jump in the player state so I need to go to my jump so I'm gonna go to jump down for example and what I'm going to do is I'm gonna reshow you how to do so you click on ADD track call Meta track we're gonna go where our script is so here we need to go to player click on OK and we have that on state reset function that we have created in the last video so here I'm gonna just reuse it by at the end of my jump animation I'm gonna right click insert key and I'm going to look for onstage results and so when the animation would have been fully played it gonna reset the state to player standard move that holds at the same time or input if we are moving and our animation if we are not moving so now that this is done because the animation is the same length on older jump what I can do is I can just say edit copy track player copy and then here I can go to jump left edit pass track I'm gonna pass it there then I can come to jump right edit pass track it could be it a year and then jump up edit pass track and it copied yeah so with that done now we should be able to jump normally so let's have a look I come here and you can see I tap on C and I can jump problem is that for now I can't jump and move at the same time so we're gonna be in need to fix that but first what I want to show you is how we can also deactivate the Collision shape because that's the thing that we need to understand here so in 2D if we were working in 3D this will not be a problem but because here we are working in 2D we need to fake the jump this is not a real jump like we are not changing the the velocity we are not changing anything we are just faking the jump because we are in a 2d environment and because we are in that 2D environment we want to disable the um the Collision shape when we're gonna jump because we maybe want to let's say that we have like the crate let's say that the crate is here maybe we want to jump over that as an obstacle and if we let the Collision shape activate it then it gonna block it dramatically so what we can do is that we can in the script we can create other function so for that I'm going to come here and I'm going to call it thunk uh I'm gonna call it clear Collision shape clear Collision I'm going to quit like this and here what I want is I want to access my Collision shape so my player is nested in this way it's created this way we have the player node and then we have audio download that are like a child of the main node player so here what I can do is I can just do dollar sign Collision shape and then here I can disable it so I can say for example disable equal to true and then we need as well to have it uh we need to have it back when we are like um when we have finished the jump so we need to create another function and this one is going to be create Collision and here I'm gonna do the exact same thing but this time it's gonna be deep disabled gonna be false so now that this is done uh we can basically do the same way so we can for example go to our animation and here on jump so I'm on jump up jump up I can go to add track converter track I can call my player here and I can click on OK and then I can just right click insert key and I can look for my clear Collision and then at the end I can write a right click insert key and I can look for my create condition so this will deactivate the Collision shape and this will recreate it so now we can just go to edit copy track uh I think this is this one so we're gonna copy it and then we can go to uh jump right edit pass track let's see it works that's the one then jump left edit pass track it works too and then here I need to go to jump down edit and pass track and so now everything works so now let's see if it deactivates when we jump so I'm gonna I'm gonna jump now you can see that it deactivate and it reactivated so now what we need to do is we need to take uh care of the the stock to be able to move while we are jumping so for moving the player now while we are jumping what we need to do is uh just add two lines of code uh for that we just need to take a look at how our move function work we have our input movement here that is a vector 2.0 and we have like a setup that input movement to be getting the vector so like when we are like pressing our right or left Arrow key all these kind of things and we have set after that velocity with like those input movements multiply by speed and we have one thing that's very important that is this line here move and slide and basically what we need to do is we just need to get that line velocity input movement time speed we need to put it into our function here jump we can just go under we need to put it like this so I'm just gonna indent it nice and then I just need to get that movement slide function and now it will work so let's have a look I'm going to launch the game and if I jump you can see that now I can jump so that's cool the problem that we have though is that when we are jumping We Can't Stop So if I do like if I release the key I don't stop like it goes until the um the jump is is resetting the state so that can be something that is good for you that something can be not good uh me I think personally it could be a good thing to keep it this way because of one simple reason which is that if we are able to interrupt the jump of while we are jumping we're gonna create problems with uh Collision shape like this so for example you can come here and let's see how it works from here and you see like it has created a sort of real weird thing and if I uh that's something we can maybe like prevent in the future video but if we leave it like this you see up it works fine so if we like coming to something it jumps nice so uh for now I don't have found like a perfect way yet to um to interrupt the jump in a way that is not creating any problem but that's something I'm gonna look after in this series of video not in the next one though because we have like a lot of other stuff to do but that's something I already know is nice and that's that's the mechanic that I've I haven't been seen uh taught a lot so I hope it has been helpful for you and me I want to thank you for watching and I will see you in the next video so see you so that's it for this video I hope it has been helpful for you if it's looking to give a thumbs up and subscribe to my channel and also check the link in the description if you want I have courses I have lots of things in the in the description so anyway I want to thank you for watching and I will see you next time bye
Info
Channel: Jean Makes Games
Views: 2,367
Rating: undefined out of 5
Keywords: rpg, actionrpg, godot rpg, rpg tutorial godot, godot 4.1, godot 4 rpg, godot rpg tutorial, godot engine tutorial, godot engine zelda, rpg jump, jump rpg, zelda jump, zelda jump 2D
Id: XOb3vil6Ycc
Channel Id: undefined
Length: 10min 32sec (632 seconds)
Published: Tue Aug 01 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.