GML [SOLVED] How to avoid exiting state machine if there is a wall ontop of my character?

Discussion in 'Programming' started by Kaijyuu, Oct 8, 2019.

  1. Kaijyuu

    Kaijyuu Member

    Joined:
    Sep 11, 2019
    Posts:
    15
    Hello, noob 856431684 here!

    Im making my first game after space rocks in GMS2 and i've "learned" state machines, basically all my animations have a state machine. the problem is that when I press "C" my character crouches OK BUT when I press "C" again and there is wall ontop of my character, she stands up and gets stuck in the wall, I've tried place_meeting(x,y-1,obj_wall) countless times with no avail. No success. Also tried place_meeting(x,y-+[1,2,3,4,5,6,7,8,9,10,....22],obj_wall) also to now avail.
    so -+ means negative and positive numers whats inside the [ ] are all numbers I tried.




    here is my code to exit the state machine:
    Code:
    
    if (place_meeting(x,y-1,obj_wall) and key_crouch)
    {
       evelyn_state = evelyn_states.evelyn_squad_lowS;
    }
    if (!place_meeting(x,y-1,obj_wall) and key_crouch)
    {
       evelyn_state = evelyn_states.evelyn_normalS;
    }
    
    I think the problem might be that my collision box is not the same to my standing collision box, since the sprite I use for crouching is 50pixelslarger (x wise) than my standing sprite, but even if I set the collision bot to be exactly the same as the "normal state - stanting" the problem persists.

    whenever I press C and a wall is ontop of me my character stands up and gets stuck. I want it to remain chouched until there is no wall ontop of my character and I press "C" again.

    all my other collisions and animations are working ok but those have the same 100x100 sprite, my crouching sprite is the only sprite that is 150x100 but the hitbox is in the exact same spot (left = 41,top = 36, right = 58, bottom = 99)
    I'll leave screenshots of my prite boxes.
    Sorry cant upload the screenshots im getting an server error!
     
    Last edited: Oct 8, 2019
  2. Kaijyuu

    Kaijyuu Member

    Joined:
    Sep 11, 2019
    Posts:
    15
    guys I have literraly no idea what happened I just posted this, watched a chapter of an anime to build the will to keep testing, sudenly eveything works perfect with no changes made....
     
  3. TheSly

    TheSly Member

    Joined:
    Jan 16, 2017
    Posts:
    990
    Essentially you need to ensure their is adequate space for the mask to change to a standing position. Before allowing the state change, check if there is space. The amount to check will depend on your mask sizes for your crouch and stand figures, but you could just test a position above the current position, and if it's free, allow them to change out of the crouch state.
    Code:
    var _size = 15;
    if !place_meeting(x, y - _size, obj_wall) evelyn_state = evelyn_states.evelyn_normalS;
    
     
    Kaijyuu likes this.
  4. Kaijyuu

    Kaijyuu Member

    Joined:
    Sep 11, 2019
    Posts:
    15
    I didnt even close GM wtf? I tested different aproched to this for like 3 hours and now suddenly it works?!!!!!
     
  5. Kaijyuu

    Kaijyuu Member

    Joined:
    Sep 11, 2019
    Posts:
    15
    Oh nice idea eventhough its working ill try this out for the sake of not using magic numbers!
     
  6. TheSly

    TheSly Member

    Joined:
    Jan 16, 2017
    Posts:
    990
    If you want to be more precise, you can also do a mask change (using mask_index), check for no collision, and if no collision, allow the state change, otherwise restore the previous mask.
     
  7. Kaijyuu

    Kaijyuu Member

    Joined:
    Sep 11, 2019
    Posts:
    15
    hmmmm I've never used that, I will certainly look into it! TY!
     

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