king javo
Member
Hi, I'm trying to figure out the best way to have my top-down player lag when changing opposite direction (180 degrees) before moving the other direction to give the appearance of momentum. So when you're running left and the move the gamepad right, I want my player to stumble and cutback left a little (basically decelerate) before starting to move right.
Anyone know how to do this? Below is my movement code with my quick attempt at trying to do it on the xaxis by comparing previous xaxis with the current xaxis.
Anyone know how to do this? Below is my movement code with my quick attempt at trying to do it on the xaxis by comparing previous xaxis with the current xaxis.
Code:
deadzone_limit = argument0;
acc = att_acceleration;
dec = att_agility;
maxSpeed = att_maxSpeed;
global.xaxis_previous = xaxis;
global.yaxis_previous = yaxis;
//if inside deadzone then decelerate
if (yaxis >= -deadzone_limit && yaxis <= deadzone_limit
&& xaxis >= -deadzone_limit && xaxis <= deadzone_limit)
{
if speed > dec
{
speed -= dec;
}
else
{
speed = 0;
}
}
else if (global.xaxis_previous != xaxis && global.xaxis_previous - xaxis == 2)
{
state = scrCutbackState;
//set time to dash
alarm[0] = room_speed/6;
}
else
{
//Player still hasn't reached top speed
if speed < maxSpeed
{
speed += acc;
}
else
{
speed = maxSpeed;
}
//point player in correct direction
direction = point_direction(0, 0, xaxis, yaxis);
}
//Control the sprite
image_speed = .2;
if (speed == 0) image_index = 0;