I'm not much of a coder so I apologize if this is a relatively simple thing to do.
I'm making a 2D action platformer with control similar to the Kirby games, like automatically being at max speed when moving, start and stop on a dime, that sort of thing. No acceleration. I need the player to be able to switch from their walking speed to a faster run speed when another key is pressed while they're moving (like pressing shift while holding left or right). I've tried a few solutions already, but nothing has worked so far and there doesn't seem to be any tutorials that have it for some reason.
Here's my code currently:
extends KinematicBody2D
const WALK_SPEED : = 1200;
const RUN_SPEED : = 1000;
const JUMP : = 1800;
const GRAVITY : = 3500;
const MAXFALLSPEED : = 80;
var velocity : = Vector2();
func input():
if Input.is_action_pressed("right"):
velocity.x = WALK_SPEED;
elif Input.is_action_pressed("left"):
velocity.x = -WALK_SPEED;
elif Input.is_action_pressed("right") and Input.is_action_pressed("run"):
velocity.x = RUN_SPEED;
elif Input.is_action_pressed("left") and Input.is_action_pressed("run"):
velocity.x = -RUN_SPEED;
else:
velocity.x = 0;
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = -JUMP;
func _physics_process(delta):
input();
velocity.y += GRAVITY * delta;
move_and_slide(velocity, Vector2.UP);
I've also tried doing it this way:
if Input.is_action_pressed("right"):
if Input.is_action_pressed("run"):
velocity.x = RUN_SPEED;
else:
velocity.x = WALK_SPEED;
elif Input.is_action_pressed("left"):
if Input.is_action_pressed("run"):
velocity.x = -RUN_SPEED;
else:
velocity.x = -WALK_SPEED;
I've tried a couple of other methods similar to above ones, but nothing so far.