1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Getting Stuck In Corners

Discussion in 'Programming' started by Hadin, Nov 9, 2019.

  1. Hadin

    Hadin Member

    Joined:
    Oct 31, 2019
    Posts:
    4
    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: Nov 9, 2019
  2. Hadin

    Hadin Member

    Joined:
    Oct 31, 2019
    Posts:
    4
    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: Nov 10, 2019 at 3:46 AM
  3. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,018
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice