• 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!

SOLVED Change of state when falling.

I'm sorry I'm using google translate.
1. The character has a "crouch" state when I hold down the down key.
2. When the character is on the falling platform and hold down key, he remains in the crouch state and does not change it.
del.png
GML:
function player_crouch_state() {
   
    show_state = "Crouch";

    vsp += global.grav;
   
    if (!is_on_ground && down_held) state = states.FALL; //Does not work!!!
   
}
if (!is_on_ground && down_held) state = states.FALL; //Does not work!!!
or
if (!is_on_ground && vsp>0) state = states.FALL; //Does not work!!!
 

Nidoking

Member
I suspect the problem is that you checked is_on_ground before moving the platform. When something that can cause the underlying condition of is_on_ground to change happens, you'll need to reassign the value of the variable. One way to do this would be to check for the grounded state at the start of this block.
 

Nidoking

Member
GML:
on_ground = place_meeting(x, y+1, obj_ground);

if (!on_ground)
{
    y += vsp;
}

// The value of on_ground is still the same, even if the instance is now on the ground.
 
о_player. in End Step on_ground();

script on_ground:
GML:
function on_ground() {

    if (place_meeting(x, y +1, o_solid)) {
        is_on_ground = true;
    }
    else {
        is_on_ground = false;
    }
  

    with(o_platform_parent) {
            if (place_meeting(x, y - 1, other) &&  !place_meeting(x, y, other))
                other.is_on_ground = true;
        }
}
script falling_platform:
GML:
function scr_falling_platform(){
    image_index = 0;
    var _this_platform = id;
    with (o_player) {
        #region If this platform is not falling.
        if (!_this_platform.start_falling) {
            if (place_meeting(x, y+1, _this_platform) && !place_meeting(x, y, _this_platform)) {
                if (_this_platform.image_index == 0) _this_platform.image_index = 1;
                if (!_this_platform.alarm[0]) _this_platform.alarm[0] = 60;
            } 
        }
        #endregion
      
        #region Platform movement.
        if (start_falling) {
            vsp = falling_speed;
            y += vsp;
        }
        #endregion
}
I think the problem is that the button is held down and it cannot get out of this state when it falls.
 

Nidoking

Member
Fine, that's when you set is_on_ground. Are you calling scr_falling_platform before or after that?

In other words, what is the sequence of these things within the step?
  • You store player inputs
  • You move the player
  • You move falling platforms
  • You set is_on_ground
I think, if you list the order in which you do those things, you might understand the problem.
 
Top