Coding

Godot Game Engine Tutorial – Make a 2D Platformer Game

  • 00:00:00 what is up guys back at again with
  • 00:00:03 another Godot tutorial let me just
  • 00:00:05 preview the game that you are gonna
  • 00:00:06 create it's uh let's see a 2d platformer
  • 00:00:10 I don't know the gender of this game I'd
  • 00:00:11 call the 2d platformer I don't care I'm
  • 00:00:14 gonna hit command beat and run the game
  • 00:00:16 just that I can preview the game I also
  • 00:00:17 did this game in unity as well I called
  • 00:00:20 it monster chase and I'm gonna call it
  • 00:00:21 monster chase here as well so we have
  • 00:00:23 our player over here he is moving and he
  • 00:00:26 needs to avoid these monsters because if
  • 00:00:27 they kill him if they get him in
  • 00:00:29 apparently I'm very good at this game
  • 00:00:31 come on man where's the monster here
  • 00:00:33 from the left side because we're
  • 00:00:34 randomizing here's another from the left
  • 00:00:36 side and one when they touches me I'm
  • 00:00:38 just gonna resize this as we can play a
  • 00:00:40 little bit better but anyways when one
  • 00:00:42 of these monsters touches me and you
  • 00:00:43 just saw I'm gonna die
  • 00:00:45 you see BAM boom I have died the game
  • 00:00:47 has restarted so basically that is the
  • 00:00:49 game but we will see how we can create
  • 00:00:52 and control our player how we can create
  • 00:00:54 these monsters how they can have their
  • 00:00:56 own AI and how we're gonna do all of the
  • 00:00:58 good stuff and you just saw so let's get
  • 00:01:01 into the videos so the first thing I'm
  • 00:01:03 gonna do is delete this editor or close
  • 00:01:07 this editor because I have another one
  • 00:01:08 and yeah don't mind my edit video
  • 00:01:11 recording software over here so voila
  • 00:01:13 here is our new project the first thing
  • 00:01:16 that I'm going to do is I'm gonna create
  • 00:01:17 a 2d scene and this one is going to be
  • 00:01:20 gameplay so I'm going to call this one
  • 00:01:21 gameplay and in the resources folder I'm
  • 00:01:23 gonna create a new folder and call it
  • 00:01:25 scenes and hit OK and in the scenes
  • 00:01:28 folder I'm gonna save the gameplay scene
  • 00:01:29 so go over there and save it now before
  • 00:01:32 we continue let's go over here and
  • 00:01:34 import these assets so these are the
  • 00:01:36 assets I'm just gonna copy them these
  • 00:01:38 rights you can download them link will
  • 00:01:39 be in the description below so make sure
  • 00:01:42 that you download these assets link will
  • 00:01:44 be in the description below and what I'm
  • 00:01:45 gonna do next is on the resources and go
  • 00:01:49 here and locate it so open file manager
  • 00:01:51 paste them so when I go back here in my
  • 00:01:54 engine they are going to
  • 00:01:56 I'm gonna click on the plus button right
  • 00:01:58 here next to gameplay to open a new
  • 00:02:01 scene because we're gonna create a
  • 00:02:02 player and here I'm going to call this
  • 00:02:04 one player because he is going to be our
  • 00:02:07 player I mean what else can I say is
  • 00:02:10 gonna be our player now in regards to
  • 00:02:12 our player I'm gonna change the type
  • 00:02:15 because currently the type is no 2d I'm
  • 00:02:17 gonna right-click on it and I'm gonna go
  • 00:02:19 here change type and I'm gonna filter
  • 00:02:21 for kinematic body to D so kinematic
  • 00:02:25 body to D because I want our player to
  • 00:02:26 be kinematic body to D command as to
  • 00:02:29 save this in the scenes folders the
  • 00:02:31 command has to save it so what is the
  • 00:02:34 first thing to do with our player first
  • 00:02:36 of all I'm gonna click on the plus
  • 00:02:38 button and here I'm gonna filter for
  • 00:02:41 animated sprite actually not sprite
  • 00:02:43 animation but animated sprite here it is
  • 00:02:45 and I'm going to call this one animation
  • 00:02:47 and let me just zoom in over here so I'm
  • 00:02:51 gonna zoom in and this is our animation
  • 00:02:54 for the player what we need to do is we
  • 00:02:56 need to click on it so click on this
  • 00:02:57 animation over here and for the frames
  • 00:02:59 we are gonna click here new frames so
  • 00:03:01 new sprite frames I'm gonna click there
  • 00:03:03 and here we can creat our sprite frames
  • 00:03:05 so the first one is gonna be idle and
  • 00:03:08 for the idle let me just go here and
  • 00:03:09 spry it's a player and I would drag this
  • 00:03:11 one so this is our idle animation so the
  • 00:03:13 first one the first frame nothing too
  • 00:03:16 complicated next right here it says idle
  • 00:03:19 you see this box or this document thing
  • 00:03:22 and it has a little plus button at the
  • 00:03:24 bottom right corner I'm going to click
  • 00:03:25 on that and it will create a new
  • 00:03:27 animation I'm going to call this one
  • 00:03:28 walk and for the walk I'm going to
  • 00:03:31 select all images from do up to seven
  • 00:03:33 and I'm going to simply drag and drop
  • 00:03:35 them over here so now selecting the
  • 00:03:37 animation over here and clicking play
  • 00:03:39 you will see that the animation is
  • 00:03:41 playing but it's playing slow so I'm
  • 00:03:43 gonna take here the frames per second
  • 00:03:46 I'm gonna say 12 which is going to make
  • 00:03:48 them you see it's gonna make them a
  • 00:03:49 little bit faster so yeah this is what I
  • 00:03:52 want and let me just go back over here
  • 00:03:54 and turn off the playing and I'm going
  • 00:03:56 to click here idle to play idle again so
  • 00:03:59 now I'm selecting the player you see we
  • 00:04:02 have this exclamation mark over here we
  • 00:04:04 need to add
  • 00:04:05 because this is a kinematic body we need
  • 00:04:06 to have a shape on it so I'm gonna
  • 00:04:08 right-click add the child node and
  • 00:04:10 filter for collision shape to D and
  • 00:04:13 attach that collision shape to D on the
  • 00:04:15 player next go here inside of our shape
  • 00:04:20 you see click on it and on the right
  • 00:04:22 side you see we have the shape I'm gonna
  • 00:04:23 click on that and I'm gonna select new
  • 00:04:25 rectangular shape and I'm gonna zoom in
  • 00:04:27 and move it something like this maybe
  • 00:04:30 move it over here and resize it so this
  • 00:04:34 is something you can do on your own this
  • 00:04:35 is nothing complicated and I'm gonna
  • 00:04:36 save it simply this is the body this is
  • 00:04:39 the shape where we are gonna detect
  • 00:04:41 collisions when it comes to our players
  • 00:04:42 so when the player touches something in
  • 00:04:45 our case a monster so when we touch a
  • 00:04:46 monster over here as you can see on the
  • 00:04:49 left or right side or up above or up
  • 00:04:52 above above down anyways we are going to
  • 00:04:57 detect that collision but we need this
  • 00:04:59 shape in order to do that so now we have
  • 00:05:01 the player and if I go here in our game
  • 00:05:03 play and take the scene here and put the
  • 00:05:07 player inside of the scene and if so I'm
  • 00:05:10 gonna call lol on this one instead of
  • 00:05:12 running the game I stop my screen
  • 00:05:14 recording software okay that was awkward
  • 00:05:16 so let us continue command B to run our
  • 00:05:19 game which was which is going to brought
  • 00:05:21 me to select which scene is going to be
  • 00:05:23 the main scene when around our game and
  • 00:05:25 it's gonna be game play so I'm gonna
  • 00:05:26 double click here and it is going to be
  • 00:05:28 game playing this is what we see now I
  • 00:05:30 am going to resize this a little bit so
  • 00:05:32 in order to resize it we need to go into
  • 00:05:34 project and project settings and here
  • 00:05:37 for in the window I'm just finding over
  • 00:05:40 here where is it where is it here it is
  • 00:05:43 window so the width of my project is
  • 00:05:46 gonna be 1280 so HD by 720 the test
  • 00:05:51 width is gonna be 640 and the test
  • 00:05:56 height is going to be 360 so half of
  • 00:06:00 this value and we're still not done
  • 00:06:02 because if I go back here and run the
  • 00:06:04 game you will see what we have you see
  • 00:06:05 you see the players over here we don't
  • 00:06:07 want that we need to go back again so
  • 00:06:09 project and project settings and at the
  • 00:06:11 bottom for the stretch it's disabled we
  • 00:06:14 need to set it a 2d and ask
  • 00:06:16 is gonna be keep and now when I come
  • 00:06:19 back command B we're gonna see our
  • 00:06:21 player and it looks really nice so now
  • 00:06:23 we have our really really cool game it
  • 00:06:26 looks I mean it looks like on the window
  • 00:06:28 for HD resolution so what is the next
  • 00:06:32 step to do let's go over here in our
  • 00:06:34 resources folder and create a new folder
  • 00:06:36 that I'm going to call scripts so
  • 00:06:38 scripts folder and inside of that folder
  • 00:06:41 I'm gonna right-click and create a new
  • 00:06:44 script I'm going to choose here c-sharp
  • 00:06:46 and let's go over here a new script and
  • 00:06:49 I'm going to call this one player and
  • 00:06:51 I'm going to hit create and it's gonna
  • 00:06:52 create it and here in the gameplay scene
  • 00:06:55 select are actually the player scene
  • 00:06:57 select the player and go here for the
  • 00:06:59 scripts and load it so from the scripts
  • 00:07:01 folder we're gonna load the player
  • 00:07:02 script then let me just double click on
  • 00:07:05 it and open it in visual studio because
  • 00:07:08 we are gonna use Visual Studio for this
  • 00:07:10 and here I'm gonna keep it in the dock
  • 00:07:13 or unfit from the dock so let's go over
  • 00:07:17 here what do we need in our player
  • 00:07:19 script what is that thing that we need
  • 00:07:22 well we always need a couple of aerial
  • 00:07:24 variables but before that let me just
  • 00:07:26 tag the class and move a little bit down
  • 00:07:28 and move this this here and this going
  • 00:07:32 to be this is not gonna be processed but
  • 00:07:35 it's gonna be physics process so we're
  • 00:07:38 gonna have a physics process and here
  • 00:07:40 above we are gonna inherit from
  • 00:07:43 kinematic body so kinematic body 2d
  • 00:07:46 instead of the node we're going to have
  • 00:07:48 a private vector 2 which is going to be
  • 00:07:50 hard movement and I'm going to call that
  • 00:07:52 one by default vector to zero next we're
  • 00:07:56 gonna have a private float which is
  • 00:07:57 going to be our move underscore speed by
  • 00:08:00 default I'm going to say it's 400 and
  • 00:08:02 these variables are self-explanatory so
  • 00:08:04 movement we're gonna use for the
  • 00:08:05 movement speed we're gonna use for the
  • 00:08:06 speed now moving forward we're gonna
  • 00:08:09 have a private float gravity which is
  • 00:08:11 gonna be equal to 20 I know gravity is
  • 00:08:14 eight point nine point eight but I don't
  • 00:08:16 care I'm going to set it in twenty
  • 00:08:17 breaking the laws of physics over here
  • 00:08:20 and we are also going to have a
  • 00:08:22 private flow this is going to be our
  • 00:08:24 jump underscore force by default I'm
  • 00:08:27 going to say negative 900 we are gonna
  • 00:08:32 have here also a private vector too
  • 00:08:36 which is going to be up directions up
  • 00:08:39 the IR is equal to vector to up like
  • 00:08:43 this and basically that's that later on
  • 00:08:46 we will have for animation here we will
  • 00:08:48 have a private animated sprite which I'm
  • 00:08:50 gonna call animation but that will come
  • 00:08:52 don't worry about that now
  • 00:08:54 inside of the player movement which is
  • 00:08:57 something that we didn't create so here
  • 00:08:59 player movement like this and inside of
  • 00:09:03 the player movement is where we are
  • 00:09:05 going to detect the input but first of
  • 00:09:07 all let me just format this and call the
  • 00:09:10 player movement inside of the physics
  • 00:09:12 process so this is where I'm going to
  • 00:09:13 call it now inside of the player move
  • 00:09:15 and what we're going to do is we're
  • 00:09:16 going to detect if our input so if input
  • 00:09:19 that is key so is key pressed and or
  • 00:09:25 actually is action so we're going to use
  • 00:09:27 an action so is action pressed and the
  • 00:09:29 action is going to be here in quotes and
  • 00:09:32 I'm going to call this one move right so
  • 00:09:36 move right and as you can assume I'm
  • 00:09:39 going to duplicate this and I'm going to
  • 00:09:40 say else if input is move left and also
  • 00:09:45 here we're going to have else so we're
  • 00:09:47 going to have all of these statements so
  • 00:09:50 what is gonna happen next what you're
  • 00:09:52 gonna do well if we're moving right
  • 00:09:54 right we're gonna move the player right
  • 00:09:56 if you ruin left we're gonna move left
  • 00:09:57 but before that we need to copy these so
  • 00:09:59 we need to go back here in our engine
  • 00:10:00 and project and project settings and
  • 00:10:03 here for the input map I'm gonna paste
  • 00:10:06 move right I'm also going to paste move
  • 00:10:09 left and I'm also going to type here
  • 00:10:11 jump so we're going to have jump as well
  • 00:10:13 now here for our move left or actually
  • 00:10:16 move right I'm going to click on the
  • 00:10:17 plus button and select the key and that
  • 00:10:19 is going to be D so I click D on my
  • 00:10:21 keyboard I'm going to click OK click on
  • 00:10:24 the plus button and key again and right
  • 00:10:26 arrow and click ok so now we have the
  • 00:10:29 right key as well or the right arrow key
  • 00:10:32 click on the plus button and key and I'm
  • 00:10:34 going to click a now and click OK and
  • 00:10:38 click on the pause button for move left
  • 00:10:39 key and left arrow which is going to say
  • 00:10:42 left that I'm going to click OK for the
  • 00:10:44 jump click on it key space ok and now we
  • 00:10:50 are good to go because now you see here
  • 00:10:52 on our move right we have the D and the
  • 00:10:54 right a move left a and left and our
  • 00:10:56 jump we have space which means in our
  • 00:10:58 game or in when we press that button so
  • 00:11:01 here for the right when we press D or or
  • 00:11:03 right arrow we're gonna move to the
  • 00:11:05 right side and here for the left if we
  • 00:11:07 press the a key or left arrow we are
  • 00:11:10 going to move to the left and when we
  • 00:11:11 press space we're gonna jump so what's
  • 00:11:13 gonna happen here in our move right is
  • 00:11:15 when we click on it we're gonna say
  • 00:11:17 movement X is equal to your move speed
  • 00:11:20 like this and when we press the left
  • 00:11:22 button we are gonna say movement X is
  • 00:11:25 equal to negative of move speed so more
  • 00:11:29 speed so now we are have we have the
  • 00:11:31 negative because the left side is the
  • 00:11:32 negative side and here we have the
  • 00:11:34 player movement I'm just going to tag it
  • 00:11:36 because at the bottom of our player
  • 00:11:37 movement we're simply going to say move
  • 00:11:39 and slide which is a built-in function
  • 00:11:42 from the kinematic body so here simply
  • 00:11:45 we're going to call movement and we are
  • 00:11:47 good to go now of course if I go back in
  • 00:11:51 our engine command B to test this out we
  • 00:11:54 are going to have some complications but
  • 00:11:55 you're going to see what you see now
  • 00:11:56 when I move you see first of all we
  • 00:11:59 don't have gravity second I'm I simply
  • 00:12:03 press the key once I'm not pressing it
  • 00:12:05 currently I released it but he's still
  • 00:12:06 moving you see press once and he is
  • 00:12:09 moving to the right or the left side
  • 00:12:10 depending on what key have I pressed so
  • 00:12:16 this is awkward as you can see we
  • 00:12:18 thought what our player to move like
  • 00:12:19 this but maybe you want if you want to
  • 00:12:21 you can leave the code like this but if
  • 00:12:22 you don't in the else when we don't
  • 00:12:25 press anything movement X is gonna be
  • 00:12:26 equal to zero because here we're going
  • 00:12:29 to reset it if I go back now and
  • 00:12:33 actually need to go back to my engine so
  • 00:12:35 command B if I go back in my engine you
  • 00:12:39 see what's gonna happen
  • 00:12:42 this and now when I release it he's
  • 00:12:43 gonna stop when I move it he is still
  • 00:12:46 there he is well stopping when I move
  • 00:12:49 him he is moving when I release it he is
  • 00:12:50 stopping so that's why I hear in the
  • 00:12:52 else statement we need to set movement X
  • 00:12:55 is equal to zero because if we don't
  • 00:12:57 want to move then we need to reset the
  • 00:12:59 movement back now also in regards to our
  • 00:13:02 gravity here we're going to say movement
  • 00:13:05 that y plus equals gravity which is
  • 00:13:08 going to apply this gravity to our
  • 00:13:10 player now as you can see it's gonna
  • 00:13:12 apply this gravity to the player and if
  • 00:13:14 I go back in our engine and command B we
  • 00:13:18 are going to see that the player will
  • 00:13:20 follow them now in order to fix that way
  • 00:13:23 to go back here in our game plane first
  • 00:13:25 of all I'm going to right click here and
  • 00:13:26 add a child node I'm simply going to add
  • 00:13:28 a node to D and this node to D I'm going
  • 00:13:33 to move it here this is going to be our
  • 00:13:35 BG parent and I'm going to duplicate one
  • 00:13:37 and another one is going to be our
  • 00:13:38 ground parent now the ground parent I'm
  • 00:13:41 going to right click on it and change
  • 00:13:43 the type is going to be a static body so
  • 00:13:46 it's going to be a static body and I'm
  • 00:13:48 going to save it but let's go over here
  • 00:13:49 for the ground parent or actually for
  • 00:13:51 the BG parent so let me just find our
  • 00:13:53 background so we have the sprites we
  • 00:13:55 have the player here is our background
  • 00:13:57 so this is our background and I'm going
  • 00:13:59 to put this one as the child of the BG
  • 00:14:02 parent now select the background and
  • 00:14:04 here I'm going to rename it to
  • 00:14:05 background one because we're gonna have
  • 00:14:07 multiple of these and let's go over here
  • 00:14:09 in the offset I'm going to click on the
  • 00:14:12 center so I don't want it to be centered
  • 00:14:14 and for the transform I'm going to say 0
  • 00:14:16 0 for X & Y and I'm going to duplicate
  • 00:14:20 it so now we have background too and for
  • 00:14:22 the transform of background two for the
  • 00:14:23 Y position I'm going to say 700 or a
  • 00:14:26 negative excuse me 720 which is going to
  • 00:14:29 move the background over here as you can
  • 00:14:31 see now how we're going to create our
  • 00:14:34 backgrounds is that we are simply going
  • 00:14:37 to move them by we are going to move
  • 00:14:39 them if I select both of them and
  • 00:14:40 duplicate them so now we have background
  • 00:14:42 3 and I'm
  • 00:14:44 to make it as a child so move it over
  • 00:14:46 here so we have back around three and
  • 00:14:48 background for if I go over here for the
  • 00:14:50 transform and on the x-axis for both of
  • 00:14:53 them I'm going to say 1280 it's gonna
  • 00:14:55 move them as you can see right over here
  • 00:14:57 so 1280 is gonna move over here
  • 00:14:58 duplicate them again so now we have five
  • 00:15:01 and six so copy these and 1280 and 1280
  • 00:15:06 how much is that I'm not good in that so
  • 00:15:08 yeah I have no idea about math so twelve
  • 00:15:12 eighty plus twelve eighty that's two
  • 00:15:15 five six zero so here I'm going to say
  • 00:15:17 two five six zero as you can see right
  • 00:15:22 here and again duplicate them so I'm
  • 00:15:24 going to duplicate it we're gonna have
  • 00:15:26 seven and eight so for these we also
  • 00:15:29 need to add 1280 so how much is that so
  • 00:15:32 1280 so let me just calculate that so
  • 00:15:35 twelve eighty three thousand eight three
  • 00:15:38 eight four zero so three eight four zero
  • 00:15:42 let's go over here do the same thing for
  • 00:15:45 these you get the point this is what you
  • 00:15:46 need to do so let me just move the ten
  • 00:15:48 over here and select the ten and nine
  • 00:15:51 add 1280 so let me say here twelve
  • 00:15:54 eighty five thousand and five thousand
  • 00:16:00 and one hundred and twenty and this is
  • 00:16:04 enough of course you're going to do the
  • 00:16:06 same thing for the right side as well so
  • 00:16:08 I'm going to duplicate here background
  • 00:16:11 one and two let me just move it down so
  • 00:16:13 now we have here no not as children of
  • 00:16:15 background ten so that current that
  • 00:16:18 needs to go over here so select these
  • 00:16:20 two and now these are going to go on the
  • 00:16:22 negative twelve eighty you get the point
  • 00:16:24 so do that up to negative so up to
  • 00:16:27 negative five thousand one hundred and
  • 00:16:30 twenty and we're gonna do the same thing
  • 00:16:32 for our ground so here for the ground
  • 00:16:34 parent I'm going to select the ground
  • 00:16:35 put it over here so this is going to be
  • 00:16:38 our ground one like this and let me just
  • 00:16:41 offset it so I'm not gonna
  • 00:16:43 that I'm going to uncensor it so to say
  • 00:16:46 so I'm going to uncentered the ground
  • 00:16:48 and the first ground I'm going to
  • 00:16:51 position at zero here and why is gonna
  • 00:16:54 be six five two so yeah this is going to
  • 00:16:58 be for our first girl I'm gonna
  • 00:16:59 duplicate it move the ground over here
  • 00:17:02 and not like this over here select it
  • 00:17:09 and I'm gonna hold shift you put it
  • 00:17:11 right next to the other one so select
  • 00:17:14 the ground and this one let me just
  • 00:17:17 select here the Y is going to be six
  • 00:17:19 five two and the X is going to be four
  • 00:17:22 hundred and fifty as you can see so 450
  • 00:17:25 and I'm gonna do that for another ground
  • 00:17:27 so let's go here for 150 that's nine
  • 00:17:29 hundred we have the grounds here
  • 00:17:31 currently we are going to have the
  • 00:17:32 grounds all over where the backgrounds
  • 00:17:34 are I'm just gonna test the players
  • 00:17:36 movement so I'm gonna test the player
  • 00:17:38 movements then I'm going to pause the
  • 00:17:40 video form all of these grounds and then
  • 00:17:42 you're going to see what we have but
  • 00:17:44 before that select the ground parent
  • 00:17:45 right click and add a child note and
  • 00:17:48 we're going to add here a collision
  • 00:17:50 shape because we need to do that and for
  • 00:17:52 the collision shape I'm gonna go here
  • 00:17:53 and select a wreck angular shape and
  • 00:17:56 it's right here so what I need to do
  • 00:17:58 with the collision shape is resize it a
  • 00:18:00 little bit take the collision shape and
  • 00:18:02 position it over here and let me just
  • 00:18:05 resize it so that it fits the ground so
  • 00:18:07 that we can land on it so if I command B
  • 00:18:10 now so command B now we stand on the
  • 00:18:14 ground you see we stand on the ground we
  • 00:18:15 can move as you can see I still cannot
  • 00:18:17 jump we will do that study from the next
  • 00:18:19 video because I wanted to create these
  • 00:18:21 grounds I wanted to create the
  • 00:18:23 backgrounds and now we are moving with
  • 00:18:25 the player and now I am going to pause
  • 00:18:28 the video form all the grounds and the
  • 00:18:30 backgrounds and come back so you can
  • 00:18:31 copy a basis or simply download the
  • 00:18:33 complete project and copy a basis all
  • 00:18:35 back be back in a moment okay
  • 00:18:37 I am back and as you can see what I did
  • 00:18:39 I simply duplicated these backgrounds
  • 00:18:42 and then I repositioned them i
  • 00:18:44 duplicated the grounds and position them
  • 00:18:46 so the difference between the grounds if
  • 00:18:47 I take the ground one you see it's at X
  • 00:18:50 position 0 Y position will be the same
  • 00:18:52 so 652 that's for every single ground so
  • 00:18:57 don't touch the Y for the X as you can
  • 00:18:59 see the position for the first one is X
  • 00:19:01 at 0 the next one is 450 which means
  • 00:19:05 every next one is at 450 units to the
  • 00:19:09 left or to the right side as you can see
  • 00:19:11 so when I move these on the left side so
  • 00:19:13 this one is going to be 450 next one is
  • 00:19:16 going to be 900 because 450 plus 450
  • 00:19:20 plus 450 is 900
  • 00:19:22 so now take 900 and add to it 450 which
  • 00:19:26 is 1,350 so add again 1 450 that's 1800
  • 00:19:32 so on and so forth you get the point
  • 00:19:33 this is to the right side to the left
  • 00:19:35 side the negative 1 is the same numbers
  • 00:19:37 but only negative so let me just find
  • 00:19:40 here this ground I believe so from
  • 00:19:42 ground 16 it's negative 450 then ground
  • 00:19:46 17 it's negative 900 then 80 negative 13
  • 00:19:50 hundred and 50 you get the point so
  • 00:19:52 you're going to do this on your own it's
  • 00:19:53 a bit tedious for you to watch me to
  • 00:19:55 create all of this it's not fun but this
  • 00:19:57 is part of game development so you need
  • 00:19:59 to do it and the same thing for our
  • 00:20:01 backgrounds so if you take a look at
  • 00:20:03 here the first background so both of
  • 00:20:06 these are at 0 for the X now for the Y
  • 00:20:09 this one is at negative 720 so that
  • 00:20:11 above one and every background that's
  • 00:20:14 above you see we have two of these so
  • 00:20:16 the one that's up it's at Y position
  • 00:20:18 negative 720 only x position would
  • 00:20:22 change and the x position will change
  • 00:20:25 for 1000 or 1280 so 1280 so if for
  • 00:20:30 example we have background one at 0 if
  • 00:20:33 we want to add the next one to it then
  • 00:20:35 it will be at X 1280 then the next one
  • 00:20:38 is at X 1280 x 2 then by 3 you get the
  • 00:20:42 point you just add to it the that value
  • 00:20:45 and it will position it right next to
  • 00:20:46 each other
  • 00:20:47 I also added this moon just so it adds a
  • 00:20:50 little bit depth to our game looks
  • 00:20:52 so yeah nothing in particular will not
  • 00:20:55 change our game our game can function
  • 00:20:57 without it but basically yeah this is
  • 00:20:58 this is setting up our level and
  • 00:21:00 creating players movements so starting
  • 00:21:03 for in the next video we're gonna
  • 00:21:04 animate the player make him jump so
  • 00:21:07 we'll see it that what is cracking
  • 00:21:09 people in the previous video we started
  • 00:21:11 our 2d platformer ish
  • 00:21:13 game and we created our level and we
  • 00:21:15 create the movement of the player but we
  • 00:21:17 didn't animate the player and we didn't
  • 00:21:18 make him jump so let's take a look at
  • 00:21:21 how we can do that so I have the player
  • 00:21:23 over here and in order to animate him we
  • 00:21:26 need to get this component or this no do
  • 00:21:28 you see animation because this is his
  • 00:21:31 animation and in order to do that we
  • 00:21:32 need to go back here and I already have
  • 00:21:35 a reference to it as you can see but we
  • 00:21:37 need to get the real reference inside of
  • 00:21:39 the ready function so I need to say here
  • 00:21:41 animation is equal to get note and not
  • 00:21:45 name get note the note type is animated
  • 00:21:49 sprite you see here this is the type of
  • 00:21:51 the known animated sprite and how do I
  • 00:21:53 know that if I go over here and how
  • 00:21:54 we're over it you see the type is
  • 00:21:56 animated sprite and now we need to
  • 00:21:59 provide the name of the node that we
  • 00:22:01 want to get so what is the name of it
  • 00:22:02 it's animation like this and let me just
  • 00:22:04 command B here to remove these so yeah
  • 00:22:07 we also need to use the jump for so that
  • 00:22:09 this right here will be removed like
  • 00:22:12 this I don't know anyways it's
  • 00:22:15 unimportant
  • 00:22:16 so we have here the animated sprite and
  • 00:22:18 we get it here from the animation what
  • 00:22:20 I'm gonna do is go below the player
  • 00:22:22 movement and here I'm going to create a
  • 00:22:24 void function that's gonna animate our
  • 00:22:27 player and I'm going to call this one
  • 00:22:29 animate movement which takes two boolean
  • 00:22:32 parameters one is gonna be bull moving
  • 00:22:35 and another one is gonna be bull move
  • 00:22:37 right and why do we need this well we'll
  • 00:22:39 see in a second first of all if we are
  • 00:22:42 moving so here if moving not move right
  • 00:22:45 but if moving moving come on finally so
  • 00:22:50 if we are moving then simply we're going
  • 00:22:53 to call animation play and we're going
  • 00:22:55 to play the walk animation how do I know
  • 00:22:57 it's walk well if I go back here you see
  • 00:23:00 I have two animations walk and idle
  • 00:23:02 as you can see over here I have selected
  • 00:23:04 walk now I have idle if you want them to
  • 00:23:06 play so if you want to play one of them
  • 00:23:07 if I want to play the walk simply click
  • 00:23:09 or call play and call walk there you go
  • 00:23:12 simple as that and here else if we are
  • 00:23:16 not moving so else if we're not moving
  • 00:23:18 simply we're going to go and call here
  • 00:23:21 idle which is going to play the idle
  • 00:23:24 animation no we are going to call this
  • 00:23:28 inside over here so let me just take
  • 00:23:31 this so here when we are moving you see
  • 00:23:34 we're moving to the right which means
  • 00:23:35 here I'm going to say true for moving
  • 00:23:37 and true moving to the right signs you
  • 00:23:39 can see move right we have here move
  • 00:23:41 right and here we're moving to the left
  • 00:23:43 so here I'm going to say true for moving
  • 00:23:45 and Falls because we're moving to the
  • 00:23:48 left side move right here is false and
  • 00:23:50 here when we stop moving we can simply
  • 00:23:53 say false here and here we can sound or
  • 00:23:55 true or false it doesn't matter because
  • 00:23:56 we will see in a second but I want to
  • 00:23:58 demonstrate you one thing so if we go
  • 00:24:00 back over here and I hit command B to
  • 00:24:03 play our game which is going to run it
  • 00:24:06 notice now when I start moving you see
  • 00:24:08 he is animated everything is cool this
  • 00:24:10 is totally normal right well wrong
  • 00:24:12 because now if I go to the left side you
  • 00:24:14 see the movie backwards except if you
  • 00:24:17 want to have this kind of functionality
  • 00:24:18 where your player is moving backwards
  • 00:24:20 for I don't know what reason because I
  • 00:24:22 don't know your weird so yeah anyways
  • 00:24:25 you see if I click or hold command D or
  • 00:24:29 command D just D or a or left arrow or a
  • 00:24:32 right Thera what's wrong with me
  • 00:24:34 you see he's moving he's being animated
  • 00:24:36 but when he goes to the left side he's
  • 00:24:38 not facing that side that's why I added
  • 00:24:41 this right here move right why well
  • 00:24:43 because if we are moving over here so
  • 00:24:46 when we are moving I'm going to also
  • 00:24:48 check if move right so if we're moving
  • 00:24:52 to the right side else if we're moving
  • 00:24:54 to the left side because if we are
  • 00:24:55 moving to the right I need to go back
  • 00:24:57 here and demonstrate that for you notice
  • 00:24:58 where the player is facing he is
  • 00:25:00 currently looking to the right side if I
  • 00:25:02 select the animation which is our
  • 00:25:04 animated sprite and go over here in the
  • 00:25:06 inspector and for the properties you see
  • 00:25:08 here I have something called flip agent
  • 00:25:10 flip V Hey H is for horizontal V is for
  • 00:25:13 vertical if I check
  • 00:25:14 is on for age you see he's gonna flip it
  • 00:25:17 and he's gonna start looking to the left
  • 00:25:19 side as you can see flip it again he's
  • 00:25:21 looking to the right side flip it again
  • 00:25:23 left side you see what I mean
  • 00:25:24 so when we flip it and by default as you
  • 00:25:27 can see how this sprite is created
  • 00:25:30 he is facing the right side so when we
  • 00:25:33 don't flip it he's gonna face the right
  • 00:25:35 side which means over here we're going
  • 00:25:37 to call animation flip age is false
  • 00:25:40 because when we don't flip it he's
  • 00:25:41 looking the right side and here else if
  • 00:25:44 we're moving to the left side we need to
  • 00:25:46 flip it because as again I said that by
  • 00:25:50 default this sprite is looking to the
  • 00:25:53 right side how it's created so if we try
  • 00:25:55 to move to the left we need to flip it
  • 00:25:56 if I go back now and command B to run
  • 00:25:59 our game you will see now when I go to
  • 00:26:02 the right he is facing the right side
  • 00:26:04 which is okay we're not flipping him but
  • 00:26:05 if we go to the left pay attention you
  • 00:26:07 see BAM he is flipping you see he is
  • 00:26:12 flipping you know flipping anyways I
  • 00:26:15 don't want to know you even though
  • 00:26:16 you're annoyed but you're here to learn
  • 00:26:18 so when we go to the right side now
  • 00:26:20 everything is cool we are not clipping
  • 00:26:22 him he is facing the right side if we go
  • 00:26:24 to the left he is also being or he's
  • 00:26:27 flipped and looking to the left side
  • 00:26:28 which brings me back here in our else
  • 00:26:30 you see here in the else statement when
  • 00:26:34 we stop moving so here this these two
  • 00:26:36 are four movements so if we move to the
  • 00:26:38 right side true is for movement and true
  • 00:26:40 and moving to the right if we are moving
  • 00:26:41 to the left so movement is true so
  • 00:26:43 you're moving and here false because
  • 00:26:45 we're we are moving to the left side but
  • 00:26:48 in the else statement we are not moving
  • 00:26:50 so here we can say false or we need to
  • 00:26:52 say false because we're not moving and
  • 00:26:54 here we can say either true or false and
  • 00:26:56 notice if I go back here and not over
  • 00:26:59 here but the command B over here you
  • 00:27:01 will notice that nothing will happen I
  • 00:27:03 can move you see he is moving and
  • 00:27:05 everything is fine if I stop the
  • 00:27:07 movement he is facing the side where I
  • 00:27:11 have stopped moving so if I'm holding a
  • 00:27:14 key and I release it he's facing the
  • 00:27:16 left and this is where he is gonna face
  • 00:27:18 when when I release the button because
  • 00:27:19 if you go over here in our animation
  • 00:27:22 or enemy movement only if we were moving
  • 00:27:24 we are going to flip him else if we are
  • 00:27:26 not moving we're not gonna flip him and
  • 00:27:28 that is basically what we are doing here
  • 00:27:31 and this is how we can this is how we
  • 00:27:35 can determine once you move when not to
  • 00:27:38 move and want to flip the character so
  • 00:27:40 moving forward what is the next step to
  • 00:27:42 do now we need to jump and in order to
  • 00:27:44 jump we have a built in function from
  • 00:27:47 our kinematic body to D so this bad boy
  • 00:27:51 over here so if I go here right above
  • 00:27:53 our move and slide and moving slide is
  • 00:27:56 also a function that we simply provide
  • 00:27:58 so we call it it's built in into
  • 00:28:00 kinematic body which will move into the
  • 00:28:03 direction where we provided and we
  • 00:28:05 provided movement here then we know we
  • 00:28:08 are getting the movement over here so if
  • 00:28:10 we press the right arrow key or the D
  • 00:28:13 key we're gonna say movement X is equal
  • 00:28:14 to MU speed if we press the a key or the
  • 00:28:16 left arrow move speed is negative so
  • 00:28:19 you're moving to the left or to the
  • 00:28:20 right if we don't press movement X is
  • 00:28:22 zero but here I'm going to test if is on
  • 00:28:25 floor so this is a built in function it
  • 00:28:28 will tell us if we are on the floor and
  • 00:28:30 if that is the case if our input that is
  • 00:28:34 key just so is action just pressed and
  • 00:28:38 that action is going to be jump and if
  • 00:28:40 you remember in the first video we said
  • 00:28:42 the jump to be equal to space so when we
  • 00:28:46 press space on our keyboard we are going
  • 00:28:49 to jump but notice here so what is the
  • 00:28:51 next thing to do we need to see movement
  • 00:28:52 that Y is going to be equal to jump
  • 00:28:55 force as simple as that you see movement
  • 00:28:57 Y is equal to jump force if I go back
  • 00:29:00 and in our game command B let's test it
  • 00:29:03 out and see if it actually works so
  • 00:29:05 command B if I jump nothing is working
  • 00:29:09 what is wrong with teacher you're crazy
  • 00:29:11 what are you doing calm down calm down
  • 00:29:13 man I'm pressing space but it is not
  • 00:29:15 working so what is the issue you see
  • 00:29:17 here if I go back you we have the jump
  • 00:29:19 and just to be 100% sure that I added
  • 00:29:23 the jump so input map here it is so we
  • 00:29:25 have the jump is space so yeah
  • 00:29:27 everything was clear but it's not
  • 00:29:28 working why well because you see here
  • 00:29:31 move and slide we need to tell it if I
  • 00:29:33 hover over
  • 00:29:34 you see I don't know if you can see the
  • 00:29:36 explanation you see here I have movement
  • 00:29:38 slide which takes a vector to your
  • 00:29:40 linear velocity but it also takes a
  • 00:29:42 vector to floor normal what does that
  • 00:29:44 mean we need to tell it where is the
  • 00:29:46 floor we know that going down so in
  • 00:29:49 Kedah engine when we go down and if I
  • 00:29:52 take here my highlight tool highlight
  • 00:29:54 going down and come on highlight so this
  • 00:30:00 is the coordinate system this is the
  • 00:30:03 y-axis this is the x-axis plus is over
  • 00:30:05 here negatives over here for the X but
  • 00:30:07 for the y- is up plus is down so when we
  • 00:30:10 go down we are going positive we were
  • 00:30:13 doing plus which means we need to tell
  • 00:30:14 in which direction is the floor and in
  • 00:30:17 order to tell that we have this right
  • 00:30:19 here up direction you see up direction
  • 00:30:22 because I'm saying up because this is a
  • 00:30:24 shortcut for writing this new vector to
  • 00:30:27 0 for the X 1 for the Y so this is that
  • 00:30:31 shortcut so if i say here vector 2 up
  • 00:30:34 it's the same thing as if I wrote vector
  • 00:30:36 2 0 for x 1 for the Y so yeah I need to
  • 00:30:40 get that out of the way but here we need
  • 00:30:42 to provide that so we need to say here
  • 00:30:44 up DRI so up the RI which essentially
  • 00:30:49 will have a positive value which means
  • 00:30:51 we're going down so now it will inform
  • 00:30:53 our kinematic body that down is the
  • 00:30:56 floor so if I go back now here and
  • 00:30:59 command B to run our game let's see if
  • 00:31:02 the floor will be detected in space you
  • 00:31:08 get the point you see now it knows where
  • 00:31:10 is the floor or the ground because we
  • 00:31:12 told it it's down it's below us but we
  • 00:31:15 also have one more issue I'm gonna go
  • 00:31:16 here and I'm going to say GD dot print
  • 00:31:18 which is it though for print and here
  • 00:31:21 I'm going to say the value is like this
  • 00:31:23 I'm going to say plus movement now this
  • 00:31:27 movement over here is our movement you
  • 00:31:30 see it's our movement over here that we
  • 00:31:33 are adding to it you see over this
  • 00:31:34 everything here that we are adding but I
  • 00:31:37 want to show you one thing if I go back
  • 00:31:38 here in our engine
  • 00:31:40 command-b notice what's gonna happen in
  • 00:31:42 the output we are going to print so
  • 00:31:44 let's go here in the output you see the
  • 00:31:46 value keeps increasing even though we
  • 00:31:48 were just standing on the ground you see
  • 00:31:49 I'm just standing if I jump you see the
  • 00:31:51 value is at the value that we provide
  • 00:31:54 but then it starts increasing and we
  • 00:31:57 don't want that so I'm just gonna close
  • 00:31:59 this you see we don't want that it's
  • 00:32:01 increasing even though it's not gonna
  • 00:32:02 hurt our game but maybe you will need it
  • 00:32:05 for something else where it will hurt
  • 00:32:07 your game if you have it like this so in
  • 00:32:09 order to fix it we need to simply see
  • 00:32:11 here movement is equal to moving slide
  • 00:32:14 and here provide well simply movement so
  • 00:32:16 everything else is gonna be the same
  • 00:32:18 except here I'm going to say movement is
  • 00:32:19 equal to move and slide and voila that
  • 00:32:22 is that so if I go back now here and
  • 00:32:24 command B so command B to run the game
  • 00:32:28 notice now what's gonna happen here in
  • 00:32:30 the output we're standing you see we're
  • 00:32:32 standing but the output is if I clear it
  • 00:32:35 you see the output is zero if I jump we
  • 00:32:37 go up to negative 90 or 80 eight hundred
  • 00:32:39 how much we set and then it's gonna go
  • 00:32:41 back down again you see if I go over
  • 00:32:44 here let me just find where we jumped or
  • 00:32:46 it did we jump here it is so we jumped
  • 00:32:50 so the value was negative nine hundred
  • 00:32:52 then it fell down because we're
  • 00:32:54 subtracting gravity as you can see over
  • 00:32:56 here we're actually adding gravity you
  • 00:32:58 see plus equals gravity then we move
  • 00:33:00 down but then when we land on the floor
  • 00:33:02 you see the movement value starts to get
  • 00:33:05 zero zero zero zero and we don't want
  • 00:33:08 that even though as I already said this
  • 00:33:10 will not hurt our game the previous one
  • 00:33:12 where we added the values but I just
  • 00:33:13 wanted to show you that in case you
  • 00:33:15 create some game on your own use this or
  • 00:33:18 you use this code that I provided over
  • 00:33:20 here and then you have issue so this is
  • 00:33:23 how you will know what the issue is and
  • 00:33:25 basically this is how we can animate and
  • 00:33:27 move our player and starting from the
  • 00:33:30 next video we will probably had the
  • 00:33:33 camera so program the moving of the
  • 00:33:34 camera then we will add enemies and yeah
  • 00:33:36 wrapping up our game if you want to
  • 00:33:38 learn more about Godot I have that in my
  • 00:33:40 team Development Academy hopefully by
  • 00:33:41 now I hope I have also blender in in
  • 00:33:43 game maker and I'm working on unreal if
  • 00:33:46 I don't have it already
  • 00:33:47 click on the link below and I probably
  • 00:33:48 have a month trial so I have one month
  • 00:33:51 trial for two dollars you can try the
  • 00:33:53 academy out for two dollars click on the
  • 00:33:55 link below and you can learn from one
  • 00:33:57 month for two dollars like yeah so yeah
  • 00:34:00 I will see you guys in another video
  • 00:34:03 what's cracking people back at again
  • 00:34:06 with our 2d platformer games so in the
  • 00:34:09 previous video we programmed the player
  • 00:34:11 jump and we also programmed animations
  • 00:34:14 now we're gonna make the camera fall the
  • 00:34:15 player because if I hit the play button
  • 00:34:17 command B to run the game we are going
  • 00:34:19 to see that while our player can go
  • 00:34:22 outside of this screen and this is not
  • 00:34:24 what we want on the camera to follow him
  • 00:34:26 that simple so uh let's take a look at
  • 00:34:29 how we can do that then by the way if
  • 00:34:31 you want to try out my Academy you can
  • 00:34:33 do that link will be in the description
  • 00:34:34 below try it out for one month for two
  • 00:34:36 bucks even if you don't want to invest
  • 00:34:38 two bucks then well yeah good luck
  • 00:34:40 learning game development so yeah anyway
  • 00:34:43 let me just go back over here why can't
  • 00:34:46 I move this a little bit down so ya know
  • 00:34:49 I can so if I go into the game played
  • 00:34:51 this is what we have this is our scene
  • 00:34:53 this right over here and let me just
  • 00:34:55 draw said I can show you what I mean so
  • 00:34:58 this over here this is our scene I'm not
  • 00:35:02 sure if you can see these lines but it's
  • 00:35:03 not important but that is what we see
  • 00:35:05 and if I go back over here and let me
  • 00:35:07 just fold all of this in the game
  • 00:35:08 playing right click and add the child
  • 00:35:10 now and I'm going to add the camera 2d
  • 00:35:12 I'm going to call this bad boy main cam
  • 00:35:15 and this main camera let me just go over
  • 00:35:18 here in the transform of it and the
  • 00:35:21 position for it is going to be 640 by
  • 00:35:26 360 because half of the width and the
  • 00:35:29 height of our screen shows we can
  • 00:35:30 position it at the center but even
  • 00:35:33 though we have the camera if I command B
  • 00:35:35 to run our game we are still gonna go
  • 00:35:37 out of the screen as you can see already
  • 00:35:40 so how can we make the camera follow the
  • 00:35:43 player first of all what I'm gonna do is
  • 00:35:45 I'm going to click on the camera and
  • 00:35:47 we're gonna create a script so let me
  • 00:35:50 just go over here the script and right
  • 00:35:51 click and create a new C sharp script
  • 00:35:54 and I'm going to call that one camera
  • 00:35:55 follow so let's go over here camera so
  • 00:35:59 camera follow and I'm going to hit
  • 00:36:02 create and of course select the main
  • 00:36:04 camera go over here at the bottom and on
  • 00:36:06 the script here where it's empty click
  • 00:36:08 here to load it and we're gonna load it
  • 00:36:10 from scripts in camera follow voila let
  • 00:36:14 me just double click this bad boy and
  • 00:36:15 open it this in our studio oh okay so
  • 00:36:20 let me just tag this and let's go here
  • 00:36:24 so what do we need everything or the
  • 00:36:26 magic is going to happen in our override
  • 00:36:29 let me just like this so that I can
  • 00:36:31 format this correctly and we're going to
  • 00:36:34 inherit from note to the instead of the
  • 00:36:36 note only so no 2d the next thing that
  • 00:36:39 we need to do is we need to get or
  • 00:36:40 create a private note 2d for our player
  • 00:36:42 so I'm going to call this one player
  • 00:36:44 target and while we are going to use it
  • 00:36:47 to get the player now also here we're
  • 00:36:49 going to have a public pool player died
  • 00:36:52 because when we die we don't want the
  • 00:36:54 camera to follow the player and here in
  • 00:36:57 our ready function we are going to say
  • 00:36:59 here player target is equal to but first
  • 00:37:02 we need to get the parent so we need to
  • 00:37:04 see your get parent because if we just
  • 00:37:06 use get node we cannot use this so here
  • 00:37:10 we say get node it's going to be no 2d
  • 00:37:13 like this and I'm going to call it
  • 00:37:15 player I cannot just say this I cannot
  • 00:37:18 just say get node Judi because the
  • 00:37:21 player is not a child of the camera get
  • 00:37:25 node so when you call yet node on a node
  • 00:37:29 or on a game object it will try to get
  • 00:37:31 the node that is a child of it that's
  • 00:37:33 why we need to get the parent and the
  • 00:37:34 parent is the game play so first we get
  • 00:37:37 the parent then we get the child and let
  • 00:37:41 me just go over here in the process if
  • 00:37:43 the player has died we are going to
  • 00:37:45 return now return me
  • 00:37:47 simply exit out of the function because
  • 00:37:50 if we have died if the player is dead
  • 00:37:52 well there is no need for us to well
  • 00:37:56 there is a need for us to continue to
  • 00:37:59 follow him and besides that we are going
  • 00:38:01 to kill the player move him out of the
  • 00:38:04 game so that will not even be possible
  • 00:38:06 so below if the player is not that we're
  • 00:38:09 going to see in your vector to temporary
  • 00:38:10 position is equal to the current
  • 00:38:12 position of our camera next we're simply
  • 00:38:16 going to say temporary position or
  • 00:38:18 actually we don't even need to do this
  • 00:38:19 we are simply going to say that bury
  • 00:38:21 position is equal to your player target
  • 00:38:23 so player target dot get the positions
  • 00:38:26 are going to get the position from the
  • 00:38:27 player target and simply we're going to
  • 00:38:29 say position of the camera is equal to
  • 00:38:31 temp and this is how we are going to
  • 00:38:33 follow it and even so we can simply do
  • 00:38:35 this so like this we don't even need
  • 00:38:38 this vector to so we can simply say
  • 00:38:40 position is equal to play your target
  • 00:38:42 get the position so if I go back here in
  • 00:38:44 my hedging command B to run it we are
  • 00:38:47 going to notice now the camera is gonna
  • 00:38:49 follow our player but that is not the
  • 00:38:52 case and I told you the camera is going
  • 00:38:53 to follow pay what is the issue now well
  • 00:38:55 the issue is we need to so in the main
  • 00:38:57 camera and we need to go over here let
  • 00:39:01 me just find where it says so position
  • 00:39:03 scale offset here it is inside of the
  • 00:39:06 camera to D so we have the offset we
  • 00:39:08 have the anchor rotating zoom we have
  • 00:39:11 something here that is called current
  • 00:39:13 let me just find it here it is current
  • 00:39:16 this needs to be checked so when you
  • 00:39:18 check that checkbox that means that the
  • 00:39:21 current camera or what we currently see
  • 00:39:23 will be the main camera so if I command
  • 00:39:25 B to run the game now we will notice
  • 00:39:28 that the camera now is following the
  • 00:39:29 player say if I move to the left you see
  • 00:39:30 the plat camera is following the player
  • 00:39:32 if I drop the camera is following the
  • 00:39:34 player if I go back over here again the
  • 00:39:37 camera is following the player as you
  • 00:39:39 can see you see you know we and now we
  • 00:39:42 have the camera following the player and
  • 00:39:45 I don't want to I don't want to resize
  • 00:39:47 it's like this so what is the next step
  • 00:39:49 to do well the next step to do is we are
  • 00:39:52 going to add our monsters energy
  • 00:39:55 and then we are going to start spawning
  • 00:39:57 I mean our game and all the good stuff
  • 00:39:58 anyways fire here for mr. calm if you
  • 00:40:00 want to try out my can't develop macadam
  • 00:40:02 e for one month you can do that two
  • 00:40:03 bucks only for that link will be in
  • 00:40:05 description below and yeah I will see
  • 00:40:09 you guys in our video
  • 00:40:11 what's up people fire your arses calm
  • 00:40:14 and in the previous video we have the
  • 00:40:16 camera following the players so what is
  • 00:40:18 the next step to do the next step is to
  • 00:40:19 create the enemies that put them in our
  • 00:40:21 game so let us see how we can do that
  • 00:40:23 but hey if you want to try my game
  • 00:40:25 villain if it were trying about I get it
  • 00:40:26 if you want to try out my game – like
  • 00:40:28 enemy so now I have it right you can do
  • 00:40:29 that for two bucks link will be in
  • 00:40:30 description below so what we can do now
  • 00:40:34 is here we're gonna click on the pause
  • 00:40:36 button so this is going to be our empty
  • 00:40:39 scene and this is where we are going to
  • 00:40:40 create our zombies now let me just
  • 00:40:42 double click on this note scene and I'm
  • 00:40:44 going to rename this once you've read
  • 00:40:46 zombie because first we are going to
  • 00:40:47 have the red zombie now well actually
  • 00:40:51 the green one whichever one you prefer
  • 00:40:52 but what is the issue here is that we
  • 00:40:56 need to change so I'm gonna right click
  • 00:40:58 and I'm going to change the type of this
  • 00:41:00 node because it is going to be a
  • 00:41:02 kinematic body so yeah kinematic body
  • 00:41:05 and I'm going to save that one here in
  • 00:41:07 the scenes folder I'm also going
  • 00:41:08 directly con it and I had the child this
  • 00:41:10 is going to be our animated sprite so
  • 00:41:13 click on the animated sprite and double
  • 00:41:14 click on it and I'm going to call this
  • 00:41:16 one animation because we're going to
  • 00:41:17 need this bad boy and the selecting the
  • 00:41:21 animated sprite let me just clear
  • 00:41:23 everything here going into the animation
  • 00:41:24 so clicking over here clicking here on
  • 00:41:26 new frames we are going to create a new
  • 00:41:28 frame this is going to be our walk
  • 00:41:30 animation and this is the green zombie
  • 00:41:32 so let's go over here and in the enemies
  • 00:41:35 for the sprites we have the zombie green
  • 00:41:37 select all these images so all the
  • 00:41:40 images and put them over here so if i
  • 00:41:42 zoom on our zombie and click here to
  • 00:41:44 play you will see now the zombies
  • 00:41:46 playing but I'm going to add 12 frames
  • 00:41:48 so that he plays a little bit faster
  • 00:41:49 because I believe 12 frames is okay yeah
  • 00:41:53 12 frames is okay you can pump it up if
  • 00:41:56 you believe it's not okay so yeah that's
  • 00:41:58 up to you I'm gonna select the green
  • 00:41:59 zombie game object and go here add know
  • 00:42:01 that I'm going to add a collision
  • 00:42:02 shape duty now for the collision shape
  • 00:42:05 2d we need to select here a shape so
  • 00:42:07 it's going to be a rectangular one and
  • 00:42:09 I'm going to simply move this over here
  • 00:42:11 in the middle and resize it so I move it
  • 00:42:13 a little bit more in the middle
  • 00:42:14 something like this and the zombies
  • 00:42:18 animation is confusing me so I need to
  • 00:42:20 uncheck it so that it doesn't play and
  • 00:42:22 now I can simply resize this dude and
  • 00:42:26 voila we are good to go so this is going
  • 00:42:28 to be our green zombie this is
  • 00:42:30 everything we need to do for him if I go
  • 00:42:32 over here in our scenes I'm going to
  • 00:42:33 duplicate the green zombie and I'm going
  • 00:42:35 to call this one red zombies are going
  • 00:42:37 to have a red zombie I'm going to
  • 00:42:39 duplicate the green zombie again and I'm
  • 00:42:41 going to call this one ghost
  • 00:42:43 so select here the red zombie and double
  • 00:42:46 click here and I'm going to change this
  • 00:42:48 one to red zombie and selecting here the
  • 00:42:52 animation for the sprite I'm going to
  • 00:42:54 select all these frames or actually I'm
  • 00:42:56 just simply going to delete all of this
  • 00:42:58 and create a new animation for the walk
  • 00:42:59 and go simply here inside of our folder
  • 00:43:04 and select all the animations for the
  • 00:43:06 red zombie and simply put them here
  • 00:43:08 that's all we need to do everything else
  • 00:43:10 is going to be the same and doing the
  • 00:43:12 same thing for the ghost so here it is
  • 00:43:14 ghost the goose goose goose goose goose
  • 00:43:16 goose goose goose goose anyways here is
  • 00:43:18 a ghost we need to do the same thing
  • 00:43:21 select the animation here delete this
  • 00:43:23 one so the walk one needs to go you
  • 00:43:25 gotta go walk or no delete notes click
  • 00:43:28 on the animation delete it click here on
  • 00:43:30 a new a phantom and I'm going to call
  • 00:43:31 this one walk let's go over here and
  • 00:43:35 12:00 our frames are going to be 12 and
  • 00:43:36 also for the red zombie over here I
  • 00:43:38 forgot that we need to put the frames at
  • 00:43:40 12 so this animation is well played and
  • 00:43:43 let's go over here in venom YZ and we
  • 00:43:46 have the ghosts select all the ghosts
  • 00:43:48 put them over here and voila but for the
  • 00:43:51 ghost we need to move this a little bit
  • 00:43:53 here something like this can do just
  • 00:43:57 resize a little bit more and if I play
  • 00:44:00 it let's go here in the animation and
  • 00:44:01 place our ghosty ghosty look at the goes
  • 00:44:06 so yeah basically these are our
  • 00:44:08 animations and I can go here inside of
  • 00:44:13 the scripts folder and right-click and I
  • 00:44:15 can create a new script this is going to
  • 00:44:17 be a new c-sharp script so let's go over
  • 00:44:19 here new script and I'm going to call
  • 00:44:21 this one monster this is going to be a
  • 00:44:23 universal script you're going to attach
  • 00:44:25 it on the go so let's go over here and
  • 00:44:27 load in scripts and monster so attach it
  • 00:44:30 on the monster red zombie select it go
  • 00:44:33 here on the scripts and load scripts and
  • 00:44:36 monster green zombie go select it go
  • 00:44:39 here scripts empty load and go under
  • 00:44:43 scripts and monster so make sure that it
  • 00:44:45 is attached on every single one of these
  • 00:44:47 enemies and let me just go over here and
  • 00:44:48 make sure that you check these
  • 00:44:50 animations so that these animations are
  • 00:44:52 playing so let's go over here the
  • 00:44:54 animations are playing and let's go in
  • 00:44:57 our visual studio and for the monster
  • 00:45:01 what do we need first of all the monster
  • 00:45:04 is also going to inherit from kinematic
  • 00:45:07 body 2d make sure it's a kinematic body
  • 00:45:09 – they don't make don't click or don't
  • 00:45:12 select kinematic body only so it's gonna
  • 00:45:15 be a kinematic body 2d let me just let
  • 00:45:19 me just put this over here so what do we
  • 00:45:22 need in order to move our zombies well
  • 00:45:26 we need to move speed so it's gonna be a
  • 00:45:27 private flow to move speed by default me
  • 00:45:29 to say 600 because I want the zombies to
  • 00:45:32 move fast as the speed of light we also
  • 00:45:34 going to have a private gravity so
  • 00:45:36 private float gravity which is going to
  • 00:45:40 be equal to 20 F we are also going to
  • 00:45:43 have a private vector so private vector
  • 00:45:45 – this is going to be our movement and
  • 00:45:47 you can see where this is going I'm
  • 00:45:49 going to do the same the similar thing I
  • 00:45:50 did for our player we are also going to
  • 00:45:52 have here privateeer actually it's gonna
  • 00:45:54 be a public one so here I'm going to say
  • 00:45:57 public bull move the left to determine
  • 00:46:00 if you're going to move left or right
  • 00:46:01 and we're also going to have a public
  • 00:46:03 bull is ghost and because we don't want
  • 00:46:07 the ghost to be at the we don't want
  • 00:46:10 those to be at the bottom or actually
  • 00:46:13 landing on the ground because the ghost
  • 00:46:14 is floating that's why we're going to
  • 00:46:16 check if we haven't go so you're also
  • 00:46:17 going to have here
  • 00:46:18 private float minimum underscore X and a
  • 00:46:20 maximum underscore X now for what you're
  • 00:46:23 going to use these well simply here in
  • 00:46:25 our gameplay I'm going to click on the
  • 00:46:27 plus here and actually no not here I'm
  • 00:46:29 going to click on this link which is
  • 00:46:31 going to allow me to let's say for
  • 00:46:32 example it adds a ghost and I'm going to
  • 00:46:34 take the ghost and somewhere over here
  • 00:46:37 okay so this is going to be the minimum
  • 00:46:40 so the minimum is going to be negative
  • 00:46:43 five thousand and ninety so that is the
  • 00:46:46 minimum X so here we can go and we can
  • 00:46:48 say minimum X is equal to negative five
  • 00:46:52 thousand and nine hundred that I said
  • 00:46:54 ninety bits actually nine hundred so I
  • 00:46:56 can take the ghost now and not let me
  • 00:46:59 just go here what did I do I put it as a
  • 00:47:01 child of the main cameras let's see
  • 00:47:03 negative five thousand nine hundred okay
  • 00:47:08 it can also be here so yeah it can be
  • 00:47:11 that value I don't care because we're
  • 00:47:14 going to cue it that's why here let me
  • 00:47:17 just go and not the background but
  • 00:47:20 select the ghost and over here let's say
  • 00:47:23 six thousand and six hundred and fifty
  • 00:47:27 six thousand six hundred and fifty is
  • 00:47:30 going to be the maximum X so let's go
  • 00:47:32 over here maximum is gonna be equal to
  • 00:47:33 this value again what we're gonna do is
  • 00:47:35 we're going to have the bounce because
  • 00:47:37 when the zombies or the ghosts or
  • 00:47:40 whatever goes out of the screen we don't
  • 00:47:43 need it anymore so we are going to kill
  • 00:47:45 it we're going to cue it and that's why
  • 00:47:47 we're using minima and a maximum what is
  • 00:47:49 gonna happen inside of the already
  • 00:47:51 function well we're going to determine
  • 00:47:52 first of all if this that name is equal
  • 00:47:57 to ghost so if the name of this game
  • 00:47:59 object or this note holding the script
  • 00:48:01 is the ghost we're going to say is ghost
  • 00:48:03 is equal to true now we're also going to
  • 00:48:05 check here if move left so move left
  • 00:48:08 right here if we are supposed to move
  • 00:48:11 left we need to say here move speed so
  • 00:48:13 move speed is gonna be multiplied equals
  • 00:48:16 two so multiply the 2 by negative 1 F
  • 00:48:19 and then we're going to see here get the
  • 00:48:22 note and the note is going to be
  • 00:48:24 animated sprite and the name of that
  • 00:48:26 note is animation and then simply we are
  • 00:48:29 going to say flip horizontal is going to
  • 00:48:31 be equal to true this is if we are
  • 00:48:33 moving to the left side if we are moving
  • 00:48:35 to the right side we're not gonna do
  • 00:48:36 this but if we're moving to the left
  • 00:48:38 then we are going to do it and simply
  • 00:48:40 here in our physics process so here I'm
  • 00:48:43 going to say underscore physics process
  • 00:48:45 this is going to be the physics process
  • 00:48:47 here we're going to say movement like
  • 00:48:50 this dot Y and we're going to say plus
  • 00:48:52 equals gravity but we are going to check
  • 00:48:56 if this is not the ghost so if not that
  • 00:48:58 goes that we are going to do that now
  • 00:49:00 pay attention here I added an
  • 00:49:02 exclamation mark what is an exclamation
  • 00:49:04 mark well it makes what's after it the
  • 00:49:06 opposite if this is ghost is true this
  • 00:49:09 will make it the opposite which means
  • 00:49:11 people make it false and voila
  • 00:49:13 but if this is ghost is false then what
  • 00:49:18 you're gonna do is well if it's a ghost
  • 00:49:21 actually if it's not the girls excuse me
  • 00:49:23 so here as you can see I'm adding is
  • 00:49:27 ghost I'm saying it to be equal to true
  • 00:49:28 if this game object or no it has the
  • 00:49:30 value or name ghost so if this is not
  • 00:49:33 the ghost you are going to add the
  • 00:49:34 gravity and as I said if this is ghost
  • 00:49:36 is true then this will make it the
  • 00:49:39 opposite which is false and this right
  • 00:49:41 here will not be executed but if this is
  • 00:49:43 ghost is false this will make it the
  • 00:49:45 opposite which is true and this will be
  • 00:49:47 executed simple as that
  • 00:49:48 and simply here I'm going to say
  • 00:49:50 movement so movement that X is equal to
  • 00:49:53 move speed and then we're simply going
  • 00:49:55 to call your movement is equal to
  • 00:49:58 movement slide and here we're going to
  • 00:50:00 pass the movement simple as that and
  • 00:50:02 that is all we need to do and we can
  • 00:50:04 test this out and not go over here here
  • 00:50:06 and in order to test it out I'm going to
  • 00:50:08 go here and let's say I attach the ghost
  • 00:50:10 so let's see let's see I have attached
  • 00:50:13 the ghost that's I'm going to put the
  • 00:50:15 ghost over here and I'm going to command
  • 00:50:17 B so let's see if this actually is going
  • 00:50:20 to work so now the ghost should come
  • 00:50:23 from our right side or left side in we
  • 00:50:25 that is the key
  • 00:50:27 but the ghost also went out of the
  • 00:50:29 screen so we need to kill the ghost
  • 00:50:31 that's why we have the bounce so let's
  • 00:50:33 go over here and what I can simply do is
  • 00:50:37 I can test if the position that X is
  • 00:50:41 greater than the maximum X or if the
  • 00:50:45 position that X is less than the minimum
  • 00:50:47 X we can Q free so we can Q free our
  • 00:50:51 zombie or the ghost or whatever again
  • 00:50:54 notice here if the position X of that
  • 00:50:56 game object be that the ghost or
  • 00:50:58 whatever if it's greater than the
  • 00:51:01 maximum X Q free or if it's lower than
  • 00:51:04 the minimum X then Q free this means
  • 00:51:07 this is an or operator or however it's
  • 00:51:11 called this means only one of these
  • 00:51:13 needs to be true so this can either be
  • 00:51:17 true or this can either be true if both
  • 00:51:19 of these are not true only then we will
  • 00:51:21 not execute this Q free but if this is
  • 00:51:23 true if only one of these is true then
  • 00:51:26 we will executing by the way notice here
  • 00:51:27 I don't I didn't add parenthesis or
  • 00:51:30 curly brackets because if you only have
  • 00:51:33 one statement after the if statement if
  • 00:51:36 you only have one line of code after
  • 00:51:37 that you don't have to call you don't
  • 00:51:40 have to call curly brackets so you can
  • 00:51:43 do it without the curly brackets but
  • 00:51:44 only if you have one line of code if you
  • 00:51:47 adhere another line of code for example
  • 00:51:49 int a is equal general 15 or 12 like
  • 00:51:51 this then this one this right here this
  • 00:51:54 in a will not be executed inside of the
  • 00:51:56 if statement so again remember that and
  • 00:52:00 we cannot test this out unfortunately we
  • 00:52:04 can I mean if we follow our D mob Jake
  • 00:52:06 and all of the good stuff but let me
  • 00:52:08 just try to do this I'm gonna run the
  • 00:52:10 game and try to run over here but since
  • 00:52:14 I've added the value to the zombie he
  • 00:52:16 will move faster than me you see he will
  • 00:52:18 move faster and let's hope and here we
  • 00:52:21 need to put the correct or arrange the
  • 00:52:25 backgrounds correctly so yeah as you can
  • 00:52:27 see we don't see him anymore you can do
  • 00:52:29 the exact same thing to put the bounce
  • 00:52:31 for the player this will be your
  • 00:52:33 homework following this tutorial so do
  • 00:52:35 the
  • 00:52:35 same thing to put the bounce on the
  • 00:52:38 player and here I made a mistake for
  • 00:52:40 these bounds yeah for the background but
  • 00:52:43 this is well easily adjustable so don't
  • 00:52:45 worry about that anyways this was about
  • 00:52:48 our monsters the next in the next we are
  • 00:52:50 going to start spawning them in our game
  • 00:52:52 then we are going to start detecting the
  • 00:52:54 collision all the good stuff anyways if
  • 00:52:56 you want to try my academy two bucks
  • 00:52:58 only click the link below and I will see
  • 00:52:59 you guys
  • 00:53:02 howdy really no people moving forward
  • 00:53:05 with our game let us start spawning the
  • 00:53:08 enemies in the game so the player can
  • 00:53:09 avoid him and all the good stuff and uh
  • 00:53:12 yeah this is getting awkward let's get
  • 00:53:15 into the game so the first things we
  • 00:53:18 need to do is go here in the scripts
  • 00:53:19 folder I'm gonna right click over here
  • 00:53:21 and you see sharp script make sure it's
  • 00:53:23 a sharp one let's go over here and I'm
  • 00:53:26 going to call this one game play so game
  • 00:53:28 play and make sure that you attach it
  • 00:53:30 here on the game play game object so
  • 00:53:31 script empty load we're gonna go under
  • 00:53:34 scripts and I'm just like the game play
  • 00:53:36 so first of all let me just double click
  • 00:53:38 it and open here in Visual Studio while
  • 00:53:40 we are waiting to open our script and
  • 00:53:43 giving space all of this here if you
  • 00:53:45 want to trav my Academy you can do that
  • 00:53:46 for two bucks link will be in the
  • 00:53:48 description below one month access for
  • 00:53:51 two bucks just to try it out and if you
  • 00:53:52 like it you can stick with it if you
  • 00:53:54 don't well then don't simple as that so
  • 00:53:57 here in our game play and we can inherit
  • 00:54:00 note it's not a problem we need first of
  • 00:54:03 all an export variable is going to be a
  • 00:54:05 private packed scene and we are going to
  • 00:54:09 have the green zombie so green zombie
  • 00:54:12 red zombie and the ghost I'm a goose
  • 00:54:16 goose goose goose goose and what is the
  • 00:54:18 next step we also need a private vector
  • 00:54:20 to spawn underscore left and we also
  • 00:54:24 need and here of course I would say new
  • 00:54:26 vector to like this and we need spawn
  • 00:54:29 right this is the position where we are
  • 00:54:31 going to spawn these game objects or
  • 00:54:33 nodes or I want to call it let me just
  • 00:54:35 go over here first
  • 00:54:36 and I am going to take let's take the
  • 00:54:40 red zombie and put it over here so
  • 00:54:42 somewhere around here we can start
  • 00:54:44 spawning this is on the left side by the
  • 00:54:45 way so
  • 00:54:46 the y axis can be 455 so here I'm going
  • 00:54:50 to say comma 455 for the Y on both here
  • 00:54:53 so comma again 455 for the Y and let's
  • 00:54:57 go back so for the left side it's
  • 00:55:00 negative 5010 or simply could be 5,000
  • 00:55:04 and it could be 5,000 so let's go over
  • 00:55:07 here and put it so what did I just do
  • 00:55:12 command V to paste it okay so negative
  • 00:55:16 5,000 this is for the left side and for
  • 00:55:18 the right side we need to go back over
  • 00:55:20 here and I need to take this bad boy so
  • 00:55:23 let's take him and put him over here
  • 00:55:28 positive six thousand three hundred and
  • 00:55:31 ninety so here it can be positive six
  • 00:55:35 thousand three hundred and ninety F this
  • 00:55:37 is where we are going to start spawning
  • 00:55:39 these or actually actually actually
  • 00:55:40 actually let me just go back probably
  • 00:55:43 here 6090 because let me just make sure
  • 00:55:48 where is the bounds for the monsters so
  • 00:55:51 yeah yeah it can be negative five
  • 00:55:53 thousand and ninety let me just go over
  • 00:55:55 here and see negative five thousand yeah
  • 00:55:58 it can be like this and here six
  • 00:55:59 thousand three hundred ninety because
  • 00:56:00 here is the positive six hundred six
  • 00:56:03 thousand six hundred and fifty so yeah
  • 00:56:05 this can do so these two are going to be
  • 00:56:08 are these are going to be where we are
  • 00:56:11 going to spawn these enemies and in
  • 00:56:14 order to spawn them we need to create a
  • 00:56:15 function so I'm gonna go over here
  • 00:56:17 remove this and I'm going to call this a
  • 00:56:19 void on monster spawn underscore spawn
  • 00:56:24 like this we are going to spawn the
  • 00:56:27 monster now how we are going to do that
  • 00:56:29 well it's gonna be very easy first of
  • 00:56:31 all here I'm going to say int a random
  • 00:56:33 enemies
  • 00:56:34 and then me it's gonna be equal to new
  • 00:56:37 random like this and I'm going to see
  • 00:56:40 here next from 0 up to 3 this is going
  • 00:56:43 to return a number between 0 and 3 but
  • 00:56:45 not including 3 so it will return 0 1 or
  • 00:56:48 2 and here we're going to say switching
  • 00:56:51 case and here I'm going to pass my
  • 00:56:52 random enemy and based on the case so
  • 00:56:56 the value case can be 0 like this so
  • 00:56:59 case 0 and like this and below in HC
  • 00:57:02 break we were going to have case 1 and
  • 00:57:04 case 2 so here case 1 and your case 2 of
  • 00:57:07 course here at the top we need to say
  • 00:57:10 monster and I'm going to call this one
  • 00:57:12 new monster so new monster is gonna be
  • 00:57:14 equal to null like this and depending on
  • 00:57:17 here if we have case 0 we're going to
  • 00:57:20 spawn a green zombie so we're going to
  • 00:57:21 say new monster is equal to green zombie
  • 00:57:24 that instance as monster like this and
  • 00:57:28 here below I'm going to duplicate this
  • 00:57:30 and this is going to be the red zombie
  • 00:57:32 and here below I'm going to duplicate it
  • 00:57:34 is and this is going to be the ghost so
  • 00:57:35 depending on the random value here from
  • 00:57:37 0 up to 2 so 0 1 or 2 we are going to
  • 00:57:41 either spawn the green zombie the red
  • 00:57:42 zombie or the ghost um girls girls girls
  • 00:57:45 girls booze anyways what we are going to
  • 00:57:47 do next is here I'm going to say vector
  • 00:57:48 2 temp he is gonna be equal to or simply
  • 00:57:51 declare it and I hear my fans going
  • 00:57:55 crazy and not fans like you are my fan
  • 00:57:58 but here let me just go and I would you
  • 00:58:03 put them over here I think this is OK
  • 00:58:05 so that we don't hear them and I don't
  • 00:58:06 have to edit this and all of the
  • 00:58:08 annoying things so the next thing that
  • 00:58:11 we need to do over here is we're going
  • 00:58:14 to again randomize here I'm going to say
  • 00:58:16 new random and I'm going to call here
  • 00:58:19 next from 0 to 2 if that number is
  • 00:58:21 greater than 0 we are going to spawn to
  • 00:58:25 the right side so here spawn to the
  • 00:58:27 right else if this number is not greater
  • 00:58:31 than 0 meaning it's a 0 so else here
  • 00:58:34 below not packed scene but this over
  • 00:58:37 here come on what you're doing like this
  • 00:58:39 else we're going to see here spawn left
  • 00:58:44 so what's gonna happen here is you're
  • 00:58:46 ready to see 10
  • 00:58:47 is equal to spawn right and here we're
  • 00:58:50 going to say temp is equal to spawn left
  • 00:58:53 like this but also here if we are
  • 00:58:56 spawning to the right side our enemy
  • 00:59:00 needs to start moving to the left side
  • 00:59:01 so what we need to do is we need to say
  • 00:59:04 here new monster that move left is equal
  • 00:59:07 to true Y again if I go over here you
  • 00:59:11 see if we spawn up to the right side
  • 00:59:13 this is on the right side you see this
  • 00:59:14 is our player and this is the right side
  • 00:59:16 so our enemy need to start moving to the
  • 00:59:18 left side so that is that that is the
  • 00:59:21 reason why so let me just remove this
  • 00:59:22 okay and practically the last thing that
  • 00:59:27 we need to see here is new monster dot
  • 00:59:29 set position we are going to pass here
  • 00:59:31 temp and add the child new monster no
  • 00:59:35 monster oh and voila now we can call
  • 00:59:40 this here in the ready function so I can
  • 00:59:41 spawn it here calling it in the ready
  • 00:59:43 function let's go over here command B
  • 00:59:45 just to see if this actually works will
  • 00:59:47 this work will this work and we have a
  • 00:59:49 debugger let me just see oh you see here
  • 00:59:53 notice we have a normal reference
  • 00:59:54 exception and the line where we have it
  • 00:59:57 it's 31 and 15 let's go into 31 and 15
  • 01:00:00 so 15 this is the line over here in 31
  • 01:00:03 okay let me just okay you see this is
  • 01:00:07 where we had that problem now the reason
  • 01:00:09 for that is this I need to go and select
  • 01:00:10 the game play I need to attach these so
  • 01:00:12 here for the green zombie drag and drop
  • 01:00:14 attach the green zombie for the red one
  • 01:00:16 drag and drop attach the red one and for
  • 01:00:19 the ghost drag and drop and attach the
  • 01:00:21 ghost ever girls girls girls girls girls
  • 01:00:23 and I'm going to command B now and
  • 01:00:25 everything works but pay attention now
  • 01:00:27 we are going to have a monster either
  • 01:00:29 from the right side or from the left
  • 01:00:31 side okay here he is so he is pawn we it
  • 01:00:35 works but we only have one that is the
  • 01:00:39 issue we only have one and in order to
  • 01:00:42 spawn more we need to call this function
  • 01:00:45 Ripley repeatedly over and over and over
  • 01:00:48 again so let's do that
  • 01:00:50 so right click here on the game play and
  • 01:00:53 I'm going to click here add a child oh
  • 01:00:55 this going to be
  • 01:00:56 timer we need to go back over here and
  • 01:00:58 this monster spawn let me just remove it
  • 01:01:01 I'm not gonna call it in the ready I'm
  • 01:01:02 gonna copy this name on monster spawn
  • 01:01:04 because I'm gonna go here select the
  • 01:01:05 timer go under his nose and signals and
  • 01:01:08 select the timeout
  • 01:01:09 connect the signal over here at the
  • 01:01:11 gameplay so connect that signal and name
  • 01:01:14 the signal on monster spawn and hit
  • 01:01:16 connect but we need to select the timer
  • 01:01:19 again go here in the inspector I'm going
  • 01:01:21 to say let's say every two seconds and
  • 01:01:23 how to start on its own one shot
  • 01:01:26 don't check this if you check it it will
  • 01:01:28 be only called once if this is not
  • 01:01:30 checked it will be called over and over
  • 01:01:31 and over again so let's see that and I'm
  • 01:01:34 going to hit command B and now we should
  • 01:01:39 see master spawning from both sides and
  • 01:01:41 every two seconds we're gonna have new
  • 01:01:43 mother okay this is a ghost ghost I'm a
  • 01:01:45 goose goose goose goose goose we can
  • 01:01:46 probably move the move the y-axis little
  • 01:01:49 bit lower so that the ghost is not that
  • 01:01:52 but you see we have one issue here one
  • 01:01:54 issue and other issues so we have issues
  • 01:01:56 here okay we have issues as you can see
  • 01:01:58 and our game is lagging and all of the
  • 01:02:00 good stuff you see okay we will see how
  • 01:02:02 we can fix this starting from the next
  • 01:02:04 video but what I'm gonna do is I'm
  • 01:02:06 simply going to go back and probably not
  • 01:02:09 4 5 5 let me just take the ghost and
  • 01:02:12 position him over here where's my ghost
  • 01:02:14 no not a child of a timer where is the
  • 01:02:17 ghost here he is
  • 01:02:19 and move the ghost over here when we
  • 01:02:21 load it down something like this can do
  • 01:02:23 transform here it's negative so oh
  • 01:02:27 actually for the why not the X here I'm
  • 01:02:30 going to say 3 5 so 5 3 5 this is going
  • 01:02:34 to be our Y or actually yeah our Y so
  • 01:02:37 here negative 5 3 5 5 3 5 so that the
  • 01:02:41 ghost is lower a little bit lower to the
  • 01:02:43 ground anyways this was our this is well
  • 01:02:46 all for this video we're spawning the
  • 01:02:47 monsters in the next video we are going
  • 01:02:49 to detect collision between the monsters
  • 01:02:50 and the player we are also going to see
  • 01:02:52 how we can avoid collisions between the
  • 01:02:55 monsters and all the good stuff if you
  • 01:02:57 want to travel my game development
  • 01:02:58 Kennedy you can do that for just two box
  • 01:03:00 one month pass for 2 dollars if you want
  • 01:03:03 it go get it if I'm not good luck
  • 01:03:05 learning game development
  • 01:03:07 that was you guys in another video what
  • 01:03:09 is a cracking people this is the last
  • 01:03:12 video of this series monster chase game
  • 01:03:14 which is a 2d platformer ish game in the
  • 01:03:17 dot game engine so let's get into it we
  • 01:03:20 need to detect division between the
  • 01:03:21 player and the zombies and kill him we
  • 01:03:23 need to also prevent collision between
  • 01:03:25 the zombies and themselves and yeah we
  • 01:03:30 also need to restart the game when the
  • 01:03:31 player dies so let's take a look at how
  • 01:03:33 we can do all of that so yeah so the
  • 01:03:35 first thing that I am going to do I am
  • 01:03:37 going to go over here in our green
  • 01:03:41 zombie and we are going to on do the
  • 01:03:46 collision with the zombies so I'm going
  • 01:03:49 to make sure that the zombies are not
  • 01:03:52 colliding with each other so we can do
  • 01:03:53 that by selecting the game the green
  • 01:03:55 zombie game object over here the
  • 01:03:56 kinematic body and here for the
  • 01:03:58 collision I am going to set the layer
  • 01:04:00 over here it is but the mask I'm going
  • 01:04:02 to move it over here so make sure that
  • 01:04:04 you move the mask over here do the same
  • 01:04:06 thing for the red zombies so let's go
  • 01:04:07 over here collision move the mask over
  • 01:04:10 here also for the ghost select him
  • 01:04:12 collision and here move the mask and
  • 01:04:15 everything is gonna be okay simple fix
  • 01:04:17 is that so if I commend B to run our
  • 01:04:20 game we are going to see now that our
  • 01:04:22 zombies are not hitting each other or
  • 01:04:25 actually they can hit each other but
  • 01:04:26 they're going to simply pass between
  • 01:04:29 each other you see okay but I can
  • 01:04:31 collide with them so I can collide with
  • 01:04:33 them so they collided with me okay now
  • 01:04:35 you see the zombie has passed then we
  • 01:04:36 have another ghost and now you saw they
  • 01:04:38 passed through each other so yeah you
  • 01:04:40 saw it I'm not gonna repeat it again you
  • 01:04:42 saw it you're not blocked okay what is
  • 01:04:45 the next step well here I'm gonna go on
  • 01:04:47 to player and select the player and
  • 01:04:49 command B or actually right-click and
  • 01:04:52 attach an area to D so I'm going to
  • 01:04:55 attach an area to D and what I'm gonna
  • 01:04:57 do is I'm going to zoom in on this
  • 01:04:59 collision shape and I'm going to
  • 01:05:01 duplicate this one and I'm going to
  • 01:05:03 resize it like this or actually no no no
  • 01:05:05 delete it why why did i duplicate it
  • 01:05:08 resize the collision like this so simply
  • 01:05:10 resize the collision like this but here
  • 01:05:13 for the area TD I'm going to right click
  • 01:05:14 and add
  • 01:05:15 another collision 2d or collision shape
  • 01:05:18 and here for the empty we're going to
  • 01:05:20 select here a wreck angular shape but
  • 01:05:24 this one this is so like this one I'm
  • 01:05:26 going to resize this bad boy let me just
  • 01:05:29 move him over here something like this
  • 01:05:32 just a little more upwards no select
  • 01:05:37 this one okay this one and voila
  • 01:05:42 so these are going to be this is going
  • 01:05:44 to be our collision now what we need to
  • 01:05:47 do is we need to create a function so
  • 01:05:49 select the collision area and go here on
  • 01:05:51 their node and here we're going to
  • 01:05:53 select this body entered so make sure
  • 01:05:55 you select that connect it with the
  • 01:05:57 player over here so connect is at the
  • 01:05:59 bottom right corner and here I'm simply
  • 01:06:01 going to call this function on body
  • 01:06:04 entered and I'm going to connect it so
  • 01:06:08 let's go into player and here I'm going
  • 01:06:11 to say void on body entered which takes
  • 01:06:13 a physics body 2d which I'm simply going
  • 01:06:15 to call body what's gonna happen over
  • 01:06:17 here well here we're going to test if
  • 01:06:19 the body so if body is in group enemy
  • 01:06:25 like this then what's gonna happen we
  • 01:06:28 are going to Q free our player but first
  • 01:06:32 of all let me just select this enemy
  • 01:06:34 copy this so we need to go back here in
  • 01:06:36 our engine select the green zombie and
  • 01:06:38 here green zombie and where it says note
  • 01:06:42 signals we have down the right side
  • 01:06:44 groups so like the group and here paste
  • 01:06:45 an enemy and click Add do the same thing
  • 01:06:48 for the red zombie so here paste add go
  • 01:06:51 here on the ghost do the same thing and
  • 01:06:53 paste it and voila we're good to go so
  • 01:06:55 what's gonna happen now if I command B
  • 01:06:58 we are gonna go over here and when one
  • 01:07:03 of the zombies or monsters touches as we
  • 01:07:05 are going to see one thing first of all
  • 01:07:07 we're going to have an error we're going
  • 01:07:09 to fix it don't worry but let me just
  • 01:07:11 show you that BAM you see we crashed our
  • 01:07:14 our app crashed what happened here well
  • 01:07:17 in the camera follow on line 23 camera
  • 01:07:20 follow line 23 this is the error the
  • 01:07:23 errors we are using the player target
  • 01:07:25 but we have died this is what
  • 01:07:26 are gonna use player died variable over
  • 01:07:28 here so when we die the first thing that
  • 01:07:30 I'm gonna do is I'm going to say get the
  • 01:07:32 parent which is the game play parent
  • 01:07:34 then I'm going to say get the node and
  • 01:07:36 the node is gonna be camera follow so
  • 01:07:39 camera follow and the name of the node
  • 01:07:42 is gonna be main cam so main camera that
  • 01:07:45 player died is equal to true so we need
  • 01:07:48 to inform it you see player died is true
  • 01:07:50 so that this right here will be true so
  • 01:07:54 if player died we're gonna hit return
  • 01:07:56 and we are not gonna follow the player
  • 01:07:57 let's check that out so command B to run
  • 01:08:00 our game again and see will that work
  • 01:08:03 so now when one of the zombies touches
  • 01:08:06 us we're gonna die but the game is not
  • 01:08:09 going to so let's go over here and now
  • 01:08:12 BAM you see I've died you see I've died
  • 01:08:14 but the game is still on the game is
  • 01:08:17 still on and we didn't crash okay so
  • 01:08:21 what is the next step we need to restart
  • 01:08:23 the game when we die and for that we're
  • 01:08:26 gonna select our game play and go inside
  • 01:08:28 so go inside of the game play and what
  • 01:08:31 we are gonna do is here below I'm going
  • 01:08:34 to create void so void underscore on
  • 01:08:38 player underscore died like this and
  • 01:08:41 here's something I'm going to say get
  • 01:08:43 the tree dot reload the current scene
  • 01:08:46 and here I'm going to simply say public
  • 01:08:49 void player died like this and I'm going
  • 01:08:55 to see here restart that start now what
  • 01:09:00 is this restart well here on top we are
  • 01:09:02 going to create a private timer that I'm
  • 01:09:05 going to call a restart like this and
  • 01:09:07 here inside of our ready function we're
  • 01:09:10 going to say restart is equal to get the
  • 01:09:12 node which is going to be our timer node
  • 01:09:14 and I'm going to call it a restart like
  • 01:09:17 this so now we need to create it so
  • 01:09:19 let's go here and let's go in our engine
  • 01:09:23 select the game play and add a child
  • 01:09:26 it's gonna be a timer and double click
  • 01:09:28 on it and rename it to restart we do
  • 01:09:31 need to copy this function name so on
  • 01:09:33 player dice to make sure that you copy
  • 01:09:35 it and selecting that on or restart go
  • 01:09:39 in
  • 01:09:39 no than signals select the timeout
  • 01:09:41 connected on the gameplay and paste here
  • 01:09:44 so we are going to pace the armed player
  • 01:09:46 dine and connect it everything is okay
  • 01:09:49 the only thing that is left for us to do
  • 01:09:51 is go back here in the inspector select
  • 01:09:53 the timer and here I'm going to check
  • 01:09:56 one shot and I'm going to see here too
  • 01:09:58 which means after two seconds we are
  • 01:10:00 going to call it so when we call over
  • 01:10:02 here so when we call restart after two
  • 01:10:04 seconds it will call this signal over
  • 01:10:06 here
  • 01:10:07 and wallah that is that and we are only
  • 01:10:10 going to call it once that's why I set
  • 01:10:12 here one shot to be true because we
  • 01:10:14 don't want to restart the game 2000
  • 01:10:15 times when the player dies and over here
  • 01:10:18 in the player when we die so we get the
  • 01:10:21 parent over here for the camera to
  • 01:10:23 inform the camera that we have died but
  • 01:10:25 we also need to say here get the parent
  • 01:10:27 which is going to be our game play and
  • 01:10:29 we need to say here player died to
  • 01:10:31 inform it that the player has died which
  • 01:10:34 will in term go back here in the game
  • 01:10:37 play it will call this right here
  • 01:10:39 restart start after two seconds it will
  • 01:10:42 call this and we will restart our game
  • 01:10:44 so if I command B now so command B let's
  • 01:10:49 take a look at here what we have so here
  • 01:10:52 and let's try to jump and now when we
  • 01:10:55 die so let me just wait over here
  • 01:10:57 because one of the monsters will show up
  • 01:10:59 eventually BAM we died boom the game has
  • 01:11:04 restart ok you see now congratulations
  • 01:11:07 you have created a 2d platformer maybe
  • 01:11:09 this is not technically a 2d platformer
  • 01:11:11 but probably some of you wise guys will
  • 01:11:14 will correct me and I don't care about
  • 01:11:15 that you're here to learn I made the 2d
  • 01:11:18 platformer because I didn't know the
  • 01:11:19 giant the genre of this game anyways you
  • 01:11:22 can download the complete project link
  • 01:11:24 will be in the description below along
  • 01:11:25 with this with the assets you can use
  • 01:11:27 them for whatever you want to use them
  • 01:11:29 of course you're gonna use it to
  • 01:11:30 probably the tutorial but
  • 01:11:31 congratulations you have created your
  • 01:11:33 first game in the game engine my brother
  • 01:11:36 and until next time bye here for message
  • 01:11:39 comm if you want to track my game dev
  • 01:11:40 Academy for 2 bucks one month click the
  • 01:11:42 link below and I will see you guys in
  • 01:11:44 another video