# GMS 2logic question about a skid state

##### Member
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, , 1.0, true)
//}
}
else
{
state = PS_IDLE
animation_play(sprite_index, , 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.0, true)
if      (image_xscale > 0) flip(-1)
else if (image_xscale < 0) flip(+1)
}``````

#### PyxelJock

##### Member
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``````