GameMaker Studio 2 - Wall Collisions

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right what we're going to do this time is we're going to work out some collisions with walls and game makers so let's get to it first we're going to start by making our character and both given some basic movements so let's just get in making a nice yellow color and call it s player and now I'm going to make an object for him and assign that sprite called the object o player let's go to the create events create a move speed variable if that value a value of 5 next go into the step events will our infants this is gonna be the key rights we're just gonna do left and right movement for this demonstration and so this gonna be keyboard check we use a and D to move left and right it's a right there's gonna be D and key left equals keyboard check poured a next we want to figure out which direction we are going based on the infant's so G da gonna create a temporary variable gonna call this mood and it's gonna be equal to KI right - cubed times new speed so this will mean that if removed to the right this value is going to be 1 times 5 so you miss basically 5 but if this is if you're holding down the left here gonna be minus 1 times 5 which is you'll be moving 5 to the left in that case and then next we'll come in to move and see that would just change our exposition by that move variable next and go into a room we'll just put our player in their wrong layer okay now check to make sure the movement is working it should be working lovely okay let's make these walls we've also going to be simple as well this could be a career square for this s wall and an object as well a wall and assign the sprite and we don't do any actual e going to do any coding in the wall itself let's play some walls in the room and see what happens whenever we're moving around see what we need to do okay so we're just moving straight through the walls so that's obviously not right if we want to bump into the walls so let's code that into our player objects it's important where we put this it needs to go in between our calculation of the direction that we're moving in before we've actually committed to the move we're gonna check for a collision before we actually move and if there is going to be a collision then we're going to cancel the roof so let's slot this in here collision check can you use a function called place meeting yeah please meeting and then we give an x and y position and but in what object we're looking for it so we're looking for the wall and the x position is going to be where we're moving to which is going to be current x position Plus this move variable that we've made up here x+ move why is just gonna be the same level and oh one and if there is a wall where we're trying to move let's cancel the move we're gonna make this new variable zero and that's going to stop us moving out spin this tall section here so let's run that and see what happens okay so we're stopping now however on the left here there's actually a little gap between the player and the wall because that condition that condition is being met and so it's making the move variable zero which means that we can't actually move any further than that because five pixels or move speeds there is a wall there so we can fix that so before we change the move value to zero in this collision check we're gonna check by one pixel if there's a wall there and if there's not then we'll move into it and we'll keep doing that until there is a wall there so to do that we're gonna check yeah not place knitting X plus sign move and this sign is gonna tell us whether this move is positive or negative and is positive and this whole thing is gonna be plus one and if this value is negative then this whole thing turns into minus one so this is only gonna be plus 1 or minus 1 anything move was zero in the whole thing zero Y is the same again and we're looking for the wall so if not basically take so if there's not a wall one pencil in the move direction then we want to actually move one pixel in the move direction X plus e cos sign new now I have made one mistake here I've used F here instead of while we want to keep doing this until this isn't true so if we change this to wile it's gonna keep looping through that until that actually is a wall one pixel to the right and then Kyle this make move zero and then everything will be great let's see that in action lovely moves nice and smoothly to side of the wall easy peasy
Info
Channel: Caz Creates
Views: 2,238
Rating: undefined out of 5
Keywords: gml, gamemaker language, gamemaker studio 2, gms2, gms, tutorial, coding, programming, help, collisions, wall collisions, game development
Id: SGED_onoxRw
Channel Id: undefined
Length: 7min 25sec (445 seconds)
Published: Fri Mar 01 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.