GMS 2 logic question about a skid state

Discussion in 'Programming' started by Shadowblitz16, Jul 12, 2017.

  1. Shadowblitz16

    Shadowblitz16 Member

    Joined:
    Jun 23, 2016
    Posts:
    596
    I have a question about the logic of entering and exiting a skid state for my player

    basicly I want mario to go into a skid state before turning around and going back into the idle or walk state
    this would only happen if the user is pressing the opposite direction of mario's x velocity and image_xscale

    in this state he will be able to fight it but if he is he will go into another skid state if he presses the opposite way he is skiding

    I'm having problems with the logic of entering and exiting the state I can seems to get it right he always is really buggy and freezes up

    here is my code
    Code:
    /// @desc player_idle()
    
    // Friction
    if (!collision_tile_bottom) { fx = VEL_FRICTION_AIR; fy = VEL_FRICTION_AIR; }
    else                        { fx = VEL_FRICTION      fy = VEL_FRICTION; }
           
    // Max Speed
    if   (Input.b) move_max = VEL_SPEED_FAST
    else          move_max = VEL_SPEED
    
    ///////////////
    // State
    ///////////////
    if (abs(Input.xaxis) > 0) 
    {
        state = PS_MOVE;
        animation_play(sprite_index, [1, 2], 0.4, true)
        flip(Input.xaxis)
    }
    else
    {
       
    }
    
    
    Code:
    /// @desc player_move()
    
    // Friction
    if (!collision_tile_bottom) { fx = VEL_FRICTION_AIR; fy = VEL_FRICTION_AIR; }
    else                        { fx = VEL_FRICTION      fy = VEL_FRICTION; }
          
    // Max Speed
    if   (Input.b) move_max = VEL_SPEED_FAST
    else          move_max = VEL_SPEED
    
    ///////////////
    // State
    ///////////////
    
    vx = clamp(vx + accel * Input.xaxis, -move_max, +move_max)
    
    if ((Input.xaxis - vx) > +1 && (Input.xaxis - vx) < -1)
    {
        //if ((sign(image_xscale) - vx) > +1 || (sign(image_xscale) - vx) < -1)
        //{
            state = PS_SKID
            animation_play(sprite_index, [13], 1.0, true)
        //}
    }
    else
    {
        state = PS_IDLE
        animation_play(sprite_index, [1], 1.0, true)
    }
    
    Code:
    /// @desc player_skid()
    
    // Friction
    if (!collision_tile_bottom) { fx = VEL_FRICTION_AIR; fy = VEL_FRICTION_AIR; }
    else                        { fx = VEL_FRICTION      fy = VEL_FRICTION; }
          
    // Max Speed
    if   (Input.b) move_max = VEL_SPEED_FAST
    else          move_max = VEL_SPEED
    
    ///////////////
    // State
    ///////////////
    if (vx > 0)    vx = clamp(vx + accel * Input.xaxis, -move_max, 0)
    if (vx < 0)    vx = clamp(vx + accel * Input.xaxis, 0, +move_max)
    
    if ((Input.xaxis - vx) != 0)
    {
    
    }
    else
    {
        state = PS_IDLE
        animation_play(sprite_index, [1], 1.0, true)
        if      (image_xscale > 0) flip(-1)
        else if (image_xscale < 0) flip(+1)
    }
    
    
     
  2. PyxelJock

    PyxelJock Member

    Joined:
    Jul 12, 2017
    Posts:
    9
    It looks like you are calling this piece of code in all states, idle, skid, and move. Are you?
    Code:
    // Friction
    if (!collision_tile_bottom) { fx = VEL_FRICTION_AIR; fy = VEL_FRICTION_AIR; }
    else                        { fx = VEL_FRICTION      fy = VEL_FRICTION; }
         
    // Max Speed
    if   (Input.b) move_max = VEL_SPEED_FAST
    else          move_max = VEL_SPEED
     
  3. Shadowblitz16

    Shadowblitz16 Member

    Joined:
    Jun 23, 2016
    Posts:
    596
    @PyxelJock yes I am.
    its there to make sure that the friction and maxspeed can change
     

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