Gamemaker Studio 2: Moving Platforms and One Way Platforms(All in One) (Intermediate)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody and welcome back to another video of our games in tech my name is Gilbert Mattos and today we're gonna be covering jump through platforms and moving platforms now I know what you might be wondering Gil you'll really cover this why are you covering it again now the reason for this is because my previous implementation of this was not very good in terms of having more than one instance of the same object being carried by the same by the same platform the other problem was that if you put the platform a little a little together a little too close together the player or the instance running the code would actually fall through them now this approach actually fixes all of that so we're gonna start from scratch and this is a little different too so there's gonna be much better you're gonna have different instances of the same object being carried by one platform without falling through and the platform's can be closer together as well so the code doesn't break okay without further ado let's get started so the first thing that we're gonna be doing is we're gonna create a sprite and there's gonna be footage on through platforms and the other ones so we're gonna name this just be our jump through right just like the previous video and we're gonna give this what we're gonna give this a not a color so we're gonna make it this kind of greenish I'm gonna give it this color okay so that is good we're gonna make sure that the origins and is in the middle Center and then after that we're gonna resize the sprite and we're gonna make it let's see we're gonna check this this is maintain aspect ratio so that we can change this so we're gonna make this let's say a hundred num the height on the width we're gonna make this like a hundred pixels okay and we're gonna hit apply now this is good as it stands after that we're gonna click on the X right here and we're gonna duplicate that this thing is pright twice 1 & 2 oops make sure that you click here and you do n 2 so that the sprite is duplicated not the word and all we have to do is change the name to what I'm doing on screen which is SPR or moving platform or we can call this H moving H moving platform something like that and we're gonna change the color right so we're gonna make it this bluish color as for the H moving platform and then we're going to the same thing for the the moving platform and it will not change the color as well trying to pick a really ugly color so this should be fine okay so everything is fine we have what we need to get started in terms of sprite and the next thing we're gonna do is we're gonna create three new objects new objects first we're gonna have Oh jump through platform well we're just gonna call it Oh Cho hub Oh jump through and that's pretty much it for that one we're gonna add a create event and we're gonna an end step event boom so here what we're gonna do is we're gonna have the one score be speed all the platform is gonna be zero and all the score RHP how the platform is gonna be zero as well and then we're gonna have the move speed of the platform right which is gonna be let's say six it could be it could before let's give them this annuity' 4 because 4 was a little bit slower and then we're gonna have the the platform direction which is gonna be chosen around them so we're gonna do choose negative one and we're gonna do one just great and but also we're gonna do so that's for this and I think that's pretty much it for this so this is to set up the other platforms next what we're gonna do is we can duplicate the same object but if we do that we're gonna have all of this so I'm just gonna create a new object and duplicate that one let's like so and now we can actually rename this object and we're gonna call it o H moving that one which is fine and we're gonna call this that's you might already guessed V moving let me just fix this is H moving platform like so and there's gonna be the moving platform like so and we assign them you know their respective sprites so this is gonna be for the V moving platform I am moving okay this is the one and this is the one great i sided the wrong thing so let me just fix that don't worry about this just gonna pull it the same a sprite boom and we're good so we don't have to do any anything else with these two objects and this is something that I should have done when I first made the other video and here we're gonna have the jump for a platformer we are going to make a switch statement right here we're gonna say switch object index and then we're gonna use the ID the names of the objects to check which one it is so we're gonna say case Oh each moving platform like so and then we're gonna say break the case again and we're gonna do OB moving platform I'm gonna do break down here just to have things so we're gonna we're gonna leave it like this but before we go we go on we're gonna go ahead and do we're gonna parent some objects right so we're gonna parent the horizontal moving platform and the vertically moving platform to this one okay so that all the code from this from this one object is actually harried by these two other objects by its children and we're gonna close this for now now what we want to do is we need to create one script you can you already have your collisions you really have your player jump and your controls so this is already set up now for anybody who already has that ongoing project you can easily adapt this into your game there's got a you know take into account some minor things so we're gonna create a new a new script and we're gonna call this jump through collisions right jump through collisions like so and then we're gonna do the following now we're going to ask for a name write an object name object name and that's pretty much it now we're gonna do with right argument zero now you might be wondering what does this mean now argument zero is what we're gonna pass into this script so this is gonna be the object let's say you know object jump through maturity yeah so let's say object jump for the platform or object whatever that's what we're gonna pass when we call the script so in this case we have with so the with statement what it does is okay so within right from inside this object that we're calling right here we're gonna run this code that's it that's inside this is curly braces so remember since we're gonna put this script inside player right the player is gonna be calling this but the code inside here is gonna be run from inside the object that we call over here I hope that's not too confusing and that's already for now so let's just move on now the next thing we need to do is is we already inside of the the pattern right we're gonna say if author that V speed is more than zero right and then we do if that place meeting I'm sorry if place meeting X Y minus other dot P speed and other right and not place meaning XY other and then we open it and close curly braces and here we're gonna run this with this while loop right we're gonna say well not place meaning X Y minus one other we're gonna say order that y+ equal to one and then over here we're gonna do all of that B speed equals zero now this is everything you need for the jump through collisions to work right so if the player starts falling does this let's start from here so notice I have used other so other is a keyword right that can be used that it's mostly used inside of the collision event but it can be also used with the with statement right so this is basically saying other which is you know the instance the object that is calling this entire thing the object that is calling the with statement is the other in this case we're accessing the players V speed from inside the platform that we're colliding with right so this is basically doing okay check that the player you know that other that's B speed is more than zero that means that we're falling so if we're falling then check that you know that it is colliding with us based on the speed right right above us and that we're also not not not clipping through the platform so let me just make this full screen so if other right if the player is not clipping right to the platform and it is you know these many pixels above above us right while the player is not colliding one pixel up right above us allow it to move down one pixel but if the player is colliding this many pixels right based on the vertical speed above us then make its vertical speed zero so this will allow the player to just stop as it touches a platform from above only above and this is pretty much what we need we don't need to do anything else for this to to for us to get this working and this is why this is actually so great this is very simple now we're gonna go back into the player we're gonna add this script we're gonna call this so we open the player object and we're going to the end step event and what a place we're going to place the script right here so we're gonna say jump through collisions right and we're gonna call the object o jump through and save it and we're gonna go into the room so we're gonna go over here we're gonna have a jump through platform so we're gonna add it right here boom and a couple of them and one right here as well boom and one right here so we can see that it's actually working and once we have that going we're gonna just run the game and see what's up and right now we should be able to jump and stay right on top of the platform and that's exactly what happening yes you can see we stay right there and we are able to jump on it now the problem with what with us being able to jump right now is that there's that one thing that I did and I forgot to remove now let me let me tell you one thing before I show you as you can see we can jump and we can go through this and now worry about just falling right through it and this is actually great because it's exactly the problem we have with the previous one so we already have the jumper platform working flawlessly so you can see there's no problem whatsoever it's working smoothly and you know that's the thing that I liked about this this newer approach know now if you were to implement this right away it wouldn't work I'm sorry the jump you jumping on it wouldn't work now let me explain why this is working so let's close the game let's go back into the player now in the player and the player object right I have this this variables now this is the variable that makes this possible so we have on the ground on ground right and it's false now in the nth step event I am setting on the ground on ground right to false at the beginning right and since game maker actually reads from top to bottom it is false here right and it keeps from being so until you change it now it says make sure we said the on ground variable true if standing on top of these objects now this is what I did here I have a check and it says if place meeting right y plus one so if we're if we are colliding with a solid object a pixel below us right said this variable to true and it's gonna continue to be true right until there's something that that says otherwise now here's that here's the other part that makes our jump or jumping code work with the jump through platforms right away remember what I told you about the the would statement so we already did this so we did with Oh jump object jumper platform so now we're running this from inside the you know they jump through platforms and it says you know if the player is above us right and it's not clipping through us and then we go ahead and set you know the players unground variable to true so these two things are turning it true right eye returning true every time this happens by the end of this line when we go back to the beginning on ground is gonna be false but we don't have to worry about that because these two up here are the ones that are turn making it true so that when we need to access them down down here we can jump so and then we just do if on ground which means you know if on ground equals true then allow us to jump you know play your jump which is basically just this if you press the jump key then vertical vertical speed equals jump force which is a negative variable so it has a negative value in it and you know that's great so far and the reason why I'm doing it I'm doing it like this is because whenever you're making your game you want to make sure that you tie that you you how you say it that you put your jump code right it's only tired to a variable right to a condition rather than an object because if I had said you know if you know place meeting you know why plus one object solid it would only work with the object solid so I have to keep on doing if place meeting you know X and then Y plus one then the name of another object you know you would have to keep on adding Ariana to the same line and even though that is something that we do up here we have the CUDA code a lot cleaner by having it here so everything else is just tied to this and you don't have to worry about anything else right and as you can see we already have that and that's a reason we can jump on the jump through platforms right away now that is pretty much it for the jump through section of the tutorial now we're gonna we're gonna be doing the vertically moving platform and the horizontal moving platform however I'm gonna be doing the horizontal moving platform first because that's a lot faster so we're gonna close all of this and we're gonna go back into the jump loop platform right now we need to code the behavior of the jump rope platform and this is very simple so we already have a platform Direction a variable right a platter variable and this you know set to either 1 negative 1 1 now we have to make sure that we run this other piece of code right here so the creative end of the player make sure that we cook we run randomized the reason why we want to run randomize is because we don't want to get the same result every time we restart the game which is not a good thing this way we can actually get different platforms moving you know a different direction now if that's not what you want that's totally fine so we're gonna continue and we're gonna code the direction of the platform so you know is what we're gonna be doing so we're gonna do eight speed right let's go eight speed equals ladder times so you're gonna put this is Sammy come here so now we have to account for the platform movement right left and right and collisions with walls so we're gonna go ahead and create a temporary variable and we're gonna call this wall collision and then we're gonna say lace meeting x+ I'll just call our HP y and then old solid right so this is what we're going to do so if the platform is going right then we're gonna be checking to the right of course based on the speed now this is the speed is negative right that is gonna check to the left so then we say a wall collision then change the direction of this the speed right so it's gonna be flattered x equals negative 1 and that is gonna change our direction right so that's going to change the direction of the platform and down here we just add to the X the platform on just for H speed and that should be pretty much it so now that's pretty much it for the movement of the platform so let's just throw some horizontally moving platforms inside the room because that's one thing that I forgot to do it always happens so so we're gonna put one here don't put them too close to the wall to start so something like this so this should do we can get rid of this for now we can just remove a bunch of them put in here so that we can actually jump on them so and then we were on the game and the movement for the platform is working just fine so far we can you know as you can see the collisions within are working just fine which is a great thing they're moving very smoothly which is a great thing so we can move along with them if we just move the player so one thing that we gotta see so you see this only works if the player is on top of one of the platforms and you don't have to worry about anything else now let's just make the player move along move along with the platform so let's just close the game so the first part is actually already done right so we're gonna go back into this let me show you this is one thing this closes so that's the movement for the platform so we're gonna create a region for this we're gonna say platform movement which is fine and then we're gonna say in region and we're gonna hide that just to make our code a lot more or elegantly placed placed so we have the platform movement there and now down here we're gonna do the following we're gonna do with a player right and then we're gonna put in the code with the player so what we need to check for is if the player is on top of the platform right so we're gonna do if place meeting say is remember the whip statement allows us allows us to run the code that is within the curly braces as if we were inside of that object so in this case is the player so imagine we're inside the player because that's exactly what is happening and it would say y plus 1 and then we say other which is you know the platform that we're colliding with underneath the player and then we say not place meaning X Y and then we should be good to go after we allow it to move now here's a thing we're gonna do X plus equals other that H speed and with this we should just run the game and be able to move along with the platform that the player is colliding with right it's on top of and only that one I run the game and we go ahead give it a try and we can move along with it fairly neat right so as you can see there's no problem there's no collision issues anywhere so this is working just great and you know the player doesn't move when the platform actually touches the walls so the player can stay right here without a problem and you would've fallen would have move forward or back it's fine now we have one problem with this method and let me show you what's the problem so because we're not checking for any walls the player can be pushed into the wall and that's a bad thing so that's the thing that we need to avoid see that so if you move well this is happening right although you can't move you know you're gonna you can get stuck with walls and that's not one thing you want so let's just correct that so once again we're gonna come back to this and we're gonna make and look check right and we're gonna say if not place meeting place meeting x+ let's say other other dot and just feed H speed Y and then old solid right and run this code out of here and that should do it for us so that should fix the entire thing and we just go ahead and run the game so if we're not colliding with any walls allow us to move right and we go ahead and as you can see we no longer get pushed against the walls just a great thing right now you can see that sometimes that does not pick so perfect just fine it's totally fine I think I don't have to worry much about that we can go for a loop if we want I think we could just do you know place meeting bla bla the same loop that we do but oddly I'll let you I'd like you to actually do the thing for this so you do whatever you want for this tutorial this should be fine I can run a while loop and you know have it be pixel perfect give me a problem but as you can see we can already move now the only issue the other issue that we have is that you can move just as fast on the direction or if not faster that the moving that platform is moving too so what's - right but if you're going against it then you're gonna move slower now this is common sense right if you have something underneath you and it's move in a certain direction you want to move in the opposite direction right and real life it's not what would happen but what happened is you would just automatically fall off now because of the way the code works remember that we're adding the speed of the platform to the player so if you're adding a speed right if you're adding a value contrary to what the edge speed of the the player is then you're gonna have some issues right to solve this we can go ahead and do and we can go ahead and make sure that the player is not pressing any keys for the platform to move them right that's the thing we can do that you can filter some other way you can actually make sure that the the speed of the player right it's negative if the player is moving to the left all right make sure you convert the platform speed based on where the player is moving and if the player is not moving then you can let it go whatever the platform wants to move the player so those are two solutions you can try I'm not gonna go over them right now but if you would like to see something like that I can maybe do something so that's for this so that's the you know collisions for this and to show you that this works for more than one instance I'm just gonna close the game and I'm gonna go into the room and I'm gonna drop two players right so I'm gonna go over here and drop two player a bunch of them actually just to show you how neat this actually is and we already have this so we got a bunch of instances of this right we can go ahead and boom something like that let me see just drop already there you go so you already have two there you got four as you can see it's not a problem it's moving as many instances as they can or as there are which is a case and this happens with all of them so there's not an issue so far just love just looking for all this right now so that's what I like to do things that work us you know as good as possible it works well so I like it so that's pretty much it for that now we can go into the horizontally vertically moving platforms so we can go ahead and remove a bunch of these guys right here boom oh I keep forgetting that you have to hold ctrl to delete these and we're gonna go back to the jumper platform again so now this is gonna be you know move the player along with the platform right so the good thing about this coat is that it is automatically going to move all the instances that you're doing the with statement with so so that's actually pretty neat I would say so now we're gonna focus on on the vertically moving platform so we can go ahead and just do one i plus y plus equal and then we do we speed you know on this quarter view speed and we can do the same thing with it on top right so it's basically gonna be three speed equals latter times V speed right I'm sorry full speed whose feet there you go I go I forgot I forgot this I get so that's for that so what else do we need we're gonna do the same thing right we're gonna say up and down wall collisions and we're gonna say please meet any same thing x y + e speed and then I'll solve it and we're gonna say it's the same thing so if up and down positions move the player with us so I was that and that moves the player with us so you just change the direction of the platform right so we're gonna say plot dirt x equals negative 1 and that's pretty much no click the movement of the platform so we're gonna go ahead grab we're vertically moving platform and we're gonna drop one a couple instances of them in here and see the interaction with the player so we just want to see the movement on the platform so far so we're gonna run the game and so far everything is working flawlessly see the player oh ok you got stuck so yeah you still cannot we still cannot move with the platform but that's fine that's easily fixable easily fixed there was a problem here I think the player was getting stuck with the platform of some reason when going down even though he was gonna step on a wall for some reason I know what I was I feel like that might have been yeah but that's fine that's fine okay so we're gonna close that and we're gonna go back to where we we're so we're gonna go back into the object doctor so now this one thing that we need to take into account here and we got to remember that the platform is gonna be going up and down right and if the player is on top of a platform we need to make sure that we don't push the player through the walls right so to fix that we can do one or two things so we're gonna take a look at the size of the player right the height to the player and make sure that the player is not it's not it is being taken into account for this to work there's no there are many ways that you can go about this so you can actually have like an offset so you can have that offset happen all the time or you can have that offset happen only when the player is on top of the platform I would say you have it all the time so you don't have to worry about anything else so we can go ahead and say we can do this right and then we can say plus right Y offset we can say a height offset offset right x platter so there's gonna be based on the plateau where the more the platform is moving right so we can go ahead and create that variable over here temporary variable so we're gonna say height offset equals let's see we can do [Music] hundred pixels let's do fifty fifty pixels okay do something like that and we can run the game again and take a look and see what happens as you can see the platform has like a little space to actually it has a lot more room for the players eyes will be on it right without a problem so let's see what happens here if we interact with the platform that's fine okay so as we said you know that you can definitely see that the space for collisions is actually much taller so we can we can do even more than that we can say 80 pixels and we got on the game again so I'll hated pixels but it looks like it works wonderfully so let's close the game let's just make sure we wrap this up inside of a region the region platform movement okay so we have that right here and then we gonna pull this in region and they should be fine so that's all you need for the movement of the platform now we're gonna do another region and we're gonna say platform and close everything so up here we're gonna say same thing as we did before we're gonna do with a player and then we're gonna do the following now we're not going to be checking just one pixel we're gonna be checking that this you know the distances in pixels that the platform is currently moving right so in this case we're gonna do in place meaning right X Y plus all did that be speed right but we're gonna have to do instead of just doing other than speed be speed we're gonna do ABS of other piece underscore V speed now let's play that now other and then we go ahead and do and not please waiting X Y and other right and we're gonna go ahead and say hey move move move away the platform + equals other than that please beep Nega my native underscore these feet just like that now let's take a look at this so ABS is the absolute value so it returns a positive value right regardless of whether you know whether it is whether it is negative or positive if it is positive is gonna return a positive number and if it is negative it's gonna return that same number but positive right just a great thing so we're checking underneath the player and that's all we need we just need to make sure that we're just you know there's amount of pixels below the platform I'm sorry above the platform right there's a platform below us this many pixels so that we can actually move along with it and that we're not you know clipping through the platform so we got to make sure that we're actually on top of it and this is gonna move us now remember what we had before we got to make sure that we're not colliding with walls so we're gonna do if let me show you first let's run the game let's see what happens cuz we got to make sure that the code works so we got this boom and as you can see whoa we went right through the platform right to the solid it's not that's not a good thing so so you can see we can you know stay on top of the platform without a problem there's no you should there whatsoever and you know that's the code for this like you know it works just fine but as I said before not only are we going through pretty much every other solid we can actually get stuck there and that's not a thing you want to do so we're also going through the other platforms but this is gonna be your homework so you're gonna you're gonna figure out how you can stop this there are easy easy ways to actually get that know from happening which is fine so your homework let me know how you accomplished is showing in the comments below you know and I will gladly reply to you okay if you have a video you can actually show it Lincoln in the comments so I think YouTube doesn't allow links so I don't know say that it isn't your channel week and not gonna take a look so let's close the game and let's just fix that issue that we're having so we're gonna be doing the same thing that we had over here so we're saying you know this place meeting so we can just copy this and you know make a few changes so that way you make your life a lot easier the way I'm doing mine right now and then so like this we tap to give that in that space and then we say we can do Y and then here we're gonna do V get rid of this here and then just put X right here and we already have what we need so we were not colliding with any solids right make sure that the platform moves up and down that means that the player is gonna fall right through the platform so that's one way to avoid the issue at hand now let me show you how cool that is look at what happens you see how the player is actually left on top of the platform without a problem pretty sweet right now you're gonna see what's gonna happen when the players on top boom baby just falls right through it and that's the way it should be so if you want to kill a player this happens and you can just basically do that you know you can put an else statement of the the first one right and say here do this do that but so far this is how you do it so I think this is pretty much it for the course not the course for the video and I hope you guys enjoy what you've seen so far we can move with the platform so you can see and you know any further issues you might have just let me know in the comments down below now let me just put up let me just put some other instances on the same player just just to show you that it can move along with the platform's right you so let's run the game once again have a bunch of the same instances boom you know they are moving just fine with the platform so you can see all of them are there and they're being moved along the y-axis right no problem whatsoever so any issues you might encounter you know you can solve them yourself you can leave a comment down below and we can discuss and that's that's pretty much it I would say right when one more thing is that you know let's create a map a tree account so if you feel like what I'm doing it's worth supporting then you can go ahead and do it if not that's totally fine with me and yeah as you can see everything has been done here in one video and I hope it's not too long for you I didn't want to make like several parts because I already have that and you don't have to go anywhere else I'm gonna make sure that everything is just time-stamped so you can actually go follow it and yeah remember if you haven't give the video a like favorite and subscribe and share it and I'll see you guys next time you
Info
Channel: Art Games and Tech
Views: 7,584
Rating: undefined out of 5
Keywords: gamemaker studio, gamemaker, gamemaker studio 2, gamemaker studio 2: Moving platforms, gamemaker studio 2: One way Platforms, gamemaker studio 2: Moving platforms and One way Platforms, GMS2, GMS, Games, Game, GameDev, Game Development, Indie Dev, Indie, gaming, coding, programming, educational, education, entertainment, platformer, platformer game, game design
Id: xzP5qqLNPag
Channel Id: undefined
Length: 42min 29sec (2549 seconds)
Published: Mon Jan 06 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.