Hello, I'm attempting to add a sprint & stamina system in an existing movement script.
Original:
What I've tried and can't seem to get working:
Most of it is working, however; when the player gets to 0 stamina, the sprite doesn't update to the spriteWalk, it stays as spriteSprint.
I'm also trying to figure out how to make the player move *2 when sprinting and then back to regular speed when stamina reaches 0.
Thank you for any help!
Original:
GML:
hSpeed = lengthdir_x(inputMagnitude * speedWalk, inputDirection);
vSpeed = lengthdir_y(inputMagnitude * speedWalk, inputDirection);
PlayerCollision();
var _oldSprite = sprite_index;
if (inputMagnitude != 0)
{
direction = inputDirection;
sprite_index = spriteWalk;
} else sprite_index = spriteIdle;
if (_oldSprite != sprite_index) localFrame = 0;
PlayerAnimateSprite();
GML:
hSpeed = lengthdir_x(inputMagnitude * speedWalk, inputDirection);
vSpeed = lengthdir_y(inputMagnitude * speedWalk, inputDirection);
PlayerCollision();
var _oldSprite = sprite_index;
if (keySprint) && (inputMagnitude != 0) && (global.stamina > 0)
{
direction = inputDirection;
sprite_index = spriteSprint;
global.stamina -= 1;
}
else if (inputMagnitude != 0)
{
direction = inputDirection;
sprite_index = spriteWalk;
}
else
{
sprite_index = spriteIdle;
}
if (_oldSprite != sprite_index) localFrame = 0;
PlayerAnimateSprite();
I'm also trying to figure out how to make the player move *2 when sprinting and then back to regular speed when stamina reaches 0.
Thank you for any help!
Last edited: