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

K

Kaijyuu

Guest
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 by a moderator:
K

Kaijyuu

Guest
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....
 

Slyddar

Member
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;
 
K

Kaijyuu

Guest
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....
I didnt even close GM wtf? I tested different aproched to this for like 3 hours and now suddenly it works?!!!!!
 
K

Kaijyuu

Guest
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;
Oh nice idea eventhough its working ill try this out for the sake of not using magic numbers!
 

Slyddar

Member
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.
 
K

Kaijyuu

Guest
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.
hmmmm I've never used that, I will certainly look into it! TY!
 
Top