• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Getting Stuck In Corners

H

Hadin

Guest
I have a basic platformer project that I'm using to learn GML. Most of it is based off online tutorials. This isn't anything except tinkering and I needed to start somewhere with no coding experience prior to using Game Maker Studio 2.

I've been having an issue where if my player walks off a ledge and turns around immediately, they'll get stuck in the corner of the wall object. It is using the basic object oriented collision you find all over the internet. So I assume it's happening because I flip the xscale and when it does it overlaps inside the wall. I've since made a workaround but I'm wondering if anyone has insight into a better solution as I assume what I'm using now is crude:

Code:
//Step Event, Before Animations:

if (hspd != 0)
{
     if (left_held && image_xscale != -1)
     {
          x += 2;
          image_xscale = -1;
     }
     else
     {
          if (right_held && image_xscale != 1)
          {
               x -= 2;
               image_xscale = 1;
          }
     }
}
I eventually plan to switch to tile collision as from my understanding it's better for simply not having a ton of objects in each room just to handle collision but for now it is what it is. Need to make art assets as is so figured this will be enough for learning other aspects of programming.

//EDIT:
I should add that I do have the sprites set up so that their collision masks are the same size for each one. The origin is off by 1 pixel since it's width is 8 pixels. I did redo the sprites so it's origin is literally centered but was still having the same issues so since reverted back to the original sprites as they looked better to me than the slightly wider version.
 
Last edited by a moderator:
H

Hadin

Guest
Sorry to ask for help. I'm really trying to figure this stuff out through tutorials and then trial and error. Things aren't always explained in a way that I can understand it though. Lacking decent algebra skills doesn't help matters either.
 
Last edited by a moderator:

TheouAegis

Member
What is your normal movement code? Your coat is telling the player to flip his scale when turning around and at the same time move to pixels and the direction you were previously facing. unless you have a collision event which is going to move the player outside of the collision once it happens, all you are doing is telling the player to move two pixels regardless of if anything is in his way. Usually, you would be setting the player speed, not directly modifying the coordinates, and then allowing a collision check to prevent the player from moving into any obstacles.
 
Top