 Then welcome to part 5 in this series I believe on 2D game design using Phaser 2D, Phaser IO. So far we've created a very simple little game and again I'm trying to keep things as simple as possible for you here but this is our game. We got two players on the screen just because we can. I'm going to refresh that you can see they fall out of gravity, they bounce, they hit those bricks, you can move them left and right, let's make them jump so that you can jump. So let's go ahead and make our code full screen, nice big font for you guys to read there. Now we have in our update function for our players here, you can see that we check left or right but now let's add another if then statement and you want this as a separate if then statement because you still want to be able to move left and right as you're jumping. Let's see if cursors up. So remember cursors is an object from the Phaser game engine that's just checking for inputs. Say here we're saying up which means our up arrow and if it is down what are we going to do? Well we're going to take in this case P which is our player, take their body dot velocity on the Y, so remember X is left and right, Y is up and down equals and we need to put in a value of how much force we want this player to have going up. Now this might get a little confusing, you think up you might think positive number, this is a negative number because remember top left corner here is zero, zero. Bottom corner here is 1080 by 720 or whatever I made the size of this level at. So this up here on the Y axis is zero and further down you go the higher the number goes so we actually want to pull a force up. If we were to make this a positive number it'd be forcing the player down which you may want if you have a spaceship game or something where the player is flying around but we're working on jumping so we're going to say negative and in this case I'll put in 350 because that's what I found to be a good number. Now if I restart they bounce and I can press up and they jump. I can press over and up and they jump, left, right, left, right. Now if you don't want them to be able to go left and right while they're up in the air because realistically that's not very feasible then you can move this into the same if then statement or you can have a check, well a check that we're about to do because there is another issue here. Watch me press up, I press up, I press up, we're not jumping, we're flying. So what we need to do is make sure that if we press up that not only are we pressing up but the player has to be touching the ground for them to jump. So let's go ahead and do that. We're going to come in here and we're going to go end, end, ampersand, ampersand. So we're saying if this is true and something else is true they both have to be true. In this case P for player because that's what we created in this loop we said P for player. I could have put player to make it more simple for you guys but I like typing as little as possible. So player body touching, so touching something down. So the player has to be touching something with its feet, with its bottom down for this to work. So now I'll save that and I'll go back over to our game here and refresh and as we're moving around I can move around, I can jump and if I'm on the ground again I can jump. But if I keep hitting up, well that shouldn't be happening. I did save this right? Oh that was it. I didn't click save. Click save for your savings to take effect. So now I can press up, I keep hitting up but they weren't going up but once they're back on the ground they're back on the ground. Now this is something you need to think about when you're playing your game because we have our players bouncing so if I see I'll press up just as they bounce and they won't jump again. See, do it again and jump. See it's not working. Something you might take into account, do you want your player to be able to jump when they bounce? We're going to keep it simple here. They have to be on the ground to jump. So I can't fly away. Now if you want them to fly away you leave that out and it's no longer a jump feature, it's a fly feature. So let's go ahead and come in here and just so we know, we'll just put a little comment here, jump controls. Okay, so we got our players, they can jump, they can move left and right. I want to point something out though just so you don't come across this and it causes problems. I'm going to come up here to our create function where we create our platform and for right now I'm going to comment that out. Okay, so now our bricks will be gone. So now look, they're falling. They're on the ground, right? I press up. Oh, now why aren't they jumping? I can move left and right. Why can't I jump? Because the game engine doesn't recognize the world bounds as them touching something on their down, on their bottom. Their bodies aren't touching anything on the bottom. Even though they're stopped, it doesn't recognize it like that. So make sure that there is a ground plane for them to fall and don't think, oh, I don't need a ground plane. They're just going to be running and I'll make them jump. You could do that, but then you can't tell it when not to jump in this fashion. So I'll go back in here, remove those comment tags and refresh. And now we have our game and they are jumping. Yay! Okay, that's it for this tourno, it was kind of a short one. But have fun, play with that, play with the numbers, play with how they react. You can even technically give them each their own jump force, different number, so they can jump at different heights. In fact, that might be what the next video will be on. We'll see. I'm kind of making this up as I go along. Thanks for watching and as always, if you do enjoy this video, check out the whole series. There should be a link in the playlist or in the description. There should be a link to the playlist in the description of this video. And what it's going to do is bring you to all the videos, but I'm going to see a new video each week. So if you want to see the videos earlier, think about becoming a Patreon supporter over at patreon.com forward slash mail x1000 and you can get videos early and download them ad free. If you cannot support me financially but you like my videos, be sure to like, subscribe, share, comment. I do appreciate it. This is filmsbychrist.com. That's Chris with a K. There should be a link to that in the description as well. And as always, I hope that you have a great day.