1 00:00:00,000 --> 00:00:08,960 hello in this video tutorial I'm going to show you how to make the vertical motion and I will 2 00:00:08,960 --> 00:00:17,480 do it for a kind of platformer game so it's going to be some jumping well we have already made a 3 00:00:17,480 --> 00:00:28,960 horizontal motion with acceleration and inertia so we start from here and I'm going to explain 4 00:00:28,960 --> 00:00:38,960 how to jump now and a platform again but former kind of game the cat will be jumping up only when 5 00:00:38,960 --> 00:00:46,760 on the ground or on a platform so we have to draw some ground and platforms so let's go into the 6 00:00:46,760 --> 00:00:56,400 backdrop here and let's draw let's say a rectangle filled with some color and that's going to be our 7 00:00:56,400 --> 00:01:07,880 ground and let's say we draw a platformer line here and let's say another platformer line there 8 00:01:13,800 --> 00:01:15,680 so let's make this a little thicker 9 00:01:15,680 --> 00:01:31,600 okay now we got some grounds and platforms so as I was saying the cat is only going to 10 00:01:31,600 --> 00:01:38,160 jump up if it's on standing on a platform or a ground that means touching the green color so 11 00:01:38,160 --> 00:01:46,560 we're going to control and use an if touching the color but then instead of using just if touching 12 00:01:46,560 --> 00:01:52,280 the color I'm going to use the if-else because I want something to happen if it is not touching 13 00:01:52,280 --> 00:02:01,320 the color right what's going to happen if it's not touching the color that mean it's midway in a 14 00:02:01,320 --> 00:02:09,320 jump so it will fall down so here I'm going to place what happens when it's falling down and 15 00:02:09,320 --> 00:02:20,400 here I will place what happens when it can jump so first thing if touching color so the sensing 16 00:02:20,400 --> 00:02:25,120 touching color pick the right color 17 00:02:30,520 --> 00:02:40,680 and then so if it is touching the color it will jump and if it is not touching else here it will 18 00:02:40,680 --> 00:02:48,440 fall down falling down is an accelerated kind of motion because you fall faster and faster the 19 00:02:48,440 --> 00:02:54,520 higher you fall from the faster you get to the ground so we're going to use the same approach 20 00:02:54,520 --> 00:03:06,760 as we use for the accelerated horizontal motion so the motion will be accomplished by changing 21 00:03:06,760 --> 00:03:15,840 the vertical coordinate here so we're going to motion and change the vertical coordinate by as 22 00:03:15,920 --> 00:03:22,640 it's going to be accelerated this is going to be a number that change so we need a variable we're 23 00:03:22,640 --> 00:03:33,720 going to variables make a variable that's going to be called the y speed and we're going to change 24 00:03:33,720 --> 00:03:41,840 the vertical position by the value of this vertical speed and at the beginning it's going to be zero 25 00:03:46,480 --> 00:03:54,400 so now quite the same as we did with a horizontal acceleration we will use the 26 00:03:54,400 --> 00:04:02,040 vertical acceleration here for the falling down so we change the vertical speed 27 00:04:05,720 --> 00:04:14,960 and as it's going down we have to use a negative number here instead of using this minus two I've 28 00:04:15,120 --> 00:04:23,400 found out that the smaller number works better so we'll use 0.5 so you can change this number 29 00:04:23,400 --> 00:04:32,000 to make it fall down faster or slower so we have taken account of falling down so let's check it 30 00:04:32,000 --> 00:04:42,800 so if it's there and if we place this inside our forever and 31 00:04:47,520 --> 00:05:00,240 from the beginning then if it is not touching it will fall down so it's falling down at an 32 00:05:00,280 --> 00:05:11,400 accelerating rate if it falls from higher it will go faster if it's falling from lower place it will 33 00:05:11,400 --> 00:05:25,040 fall now first of all we want the fall to stop when it gets to the ground or to a platform so 34 00:05:25,040 --> 00:05:34,400 it can stand on top of it so how can we do so well we know when it's touching the color so 35 00:05:34,400 --> 00:05:46,800 first thing will be to stop the downwards motion we can stop that downwards motion by setting the 36 00:05:46,800 --> 00:05:58,480 vertical speed to zero so if touching the color it should stop so let's check it so I have to 37 00:05:58,480 --> 00:06:09,880 hit the green flag and now if it falls now it will stop because if touching green color then 38 00:06:09,880 --> 00:06:17,800 vertical variable will be zero and now stops now 39 00:06:20,520 --> 00:06:31,560 it stops there good so we have taken care of the downwards motion the falling now we have to take 40 00:06:31,560 --> 00:06:40,280 care of the upwards motion the jumping for us to make the cat jump we will use the arrow key 41 00:06:40,280 --> 00:06:43,440 up arrow key so if 42 00:06:49,320 --> 00:06:53,200 under sensing key press 43 00:06:56,160 --> 00:07:05,960 meaning up arrow key press then what then go up but we don't want it to be 44 00:07:06,200 --> 00:07:16,040 accelerating up so we don't use change the vertical speed we will set a fixed value so it 45 00:07:16,040 --> 00:07:28,320 jumps up at a fixed speed so we use set instead of change so we will make it go up at some speed 46 00:07:28,320 --> 00:07:43,560 let's say 10 right so if the arrow keys press the vertical speed will be 10 now when only if 47 00:07:43,560 --> 00:07:54,800 it is touching the ground or a platform right because we don't want it to be able to fly in 48 00:07:54,800 --> 00:08:12,760 middle air so now let's check it now I hit the up arrow and it's not going up why because I haven't 49 00:08:12,760 --> 00:08:26,320 change it here my variable to now if touching color it is speed to zero stop and then I hit 50 00:08:26,320 --> 00:08:38,920 the right arrow and it goes up like that now when I release it it falls down automatically if I keep 51 00:08:38,920 --> 00:08:46,920 hitting the arrow it doesn't go anywhere because it is not touching the green color it's in me 52 00:08:46,920 --> 00:08:56,320 there so this doesn't work so this will only work if touching color if not touching color it just 53 00:08:56,320 --> 00:09:07,720 falls down and now I can jump on top of the platforms but then there's something which is 54 00:09:07,720 --> 00:09:16,480 standing on the platforms but there's something which is quite wrong here look if I go up from 55 00:09:16,480 --> 00:09:22,760 here I'm touching the green and I can go up to the platform I'm going through the platform and 56 00:09:22,760 --> 00:09:31,040 that's not good so I have to prevent the cat from going through the platform somehow how can I do 57 00:09:31,040 --> 00:09:37,680 it well one simple way would be to use a different color for the underside of the platform so I'm 58 00:09:37,680 --> 00:09:46,040 going to use a red color here and draw a rectangle underneath the platform 59 00:09:52,560 --> 00:10:06,320 like that and then if I touch that color I will make the cat go down like bouncing back 60 00:10:06,760 --> 00:10:08,440 so I use if 61 00:10:14,520 --> 00:10:19,920 and I put this inside the same forever here now touching color 62 00:10:22,440 --> 00:10:27,760 now this other color I will pick it 63 00:10:27,760 --> 00:10:43,120 then what then something fall down so this is the falling down block so duplicated but 64 00:10:43,120 --> 00:10:56,880 now if I want to make the bouncing back different from falling down I can just make this faster so 65 00:10:56,880 --> 00:11:05,640 I can use let's say minus five so let's have a look at it now I move under the platform I go up 66 00:11:05,640 --> 00:11:16,520 and it will bounce back faster than falling look this is falling and this is bouncing back now you 67 00:11:16,520 --> 00:11:21,680 have to pick the right angle for you to be able to jump into that 68 00:11:27,640 --> 00:11:39,720 okay well so let's recollect we are making the upwards motion using change vertical value 69 00:11:39,880 --> 00:11:50,640 coordinate with a variable speed here vertical speed this is zero at the beginning only if you 70 00:11:50,640 --> 00:12:01,960 touch in the ground or a platform color then you can make it go up by setting the vertical value 71 00:12:02,680 --> 00:12:15,440 to 10 if touching color it will make it zero so when it falls down it will stop there and 72 00:12:15,440 --> 00:12:28,200 if not touching the color it will automatically accelerate downwards now to prevent the cat 73 00:12:28,200 --> 00:12:33,560 from going through the underside of the platform we use a different color and if 74 00:12:33,560 --> 00:12:44,200 touching that color we make it fall down even faster than when in midair and what with this 75 00:12:44,200 --> 00:12:51,760 you can make a jumping kind of game you can of course include more sprites so if you get them 76 00:12:51,800 --> 00:13:00,120 you can get points you can put some kind of lava floor so if you jump into it you 77 00:13:00,120 --> 00:13:05,080 you die and so on okay thank you