I've been using some code that allows the player to walk and run by basically changing their movement speed if a second button is held down while moving (I've stripped out some extra code to show the bare bones of it):
func _physics_process(delta):
#MOVEMENT
if Input.is_action_pressed("right"):
if Input.is_action_pressed("run"):
velocity.x = runSpeed;
else:
velocity.x = walkSpeed;
elif Input.is_action_pressed("left"):
if Input.is_action_pressed("run"):
velocity.x = -runSpeed;
else:
velocity.x = -walkSpeed;
else:
if is_on_floor():
velocity.x = 0;
This largely works, but I'm wondering if there's a more easier/cleaner way of going about it. I'm asking because I've yet to see a tutorial that actually uses more than one movement speed. The vast majority of tutorials I see use only one fixed movement speed and never go beyond that, usually using something along the lines of
Input.get_action_strength("right") - Input.get_action_strength("left")
which I guess works okay, but that's not enough for what I need and I've never figured out how to get both a walk and a run function from it without something going wrong, hence why I use all the code above.