How do I code Sprint in a 2D platformer

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Rh0alex

extends KinematicBody2D

const speed = 400
const jump = -350
const gravity = 20
const sprint = 600

const UP = Vector2(0, -1)
var motion = Vector2()

func _physics_process(_delta):
motion.y += gravity

if Input.is_action_pressed("right"):
	motion.x = speed

elif Input.is_action_pressed("left"):
	motion.x = -speed
else:
	motion.x = 0
	

if is_on_floor():
	if Input.is_action_just_pressed("jump"):
		motion.y = jump


motion = move_and_slide(motion, UP)
:bust_in_silhouette: Reply From: lettucing

this should work

if Input.is_action_pressed("right"):
    if Input.is_action_pressed("sprint_keybind"):
        motion.x = sprint
    else:
        motion.x = speed

if Input.is_action_pressed("left"):
    if Input.is_action_pressed("sprint_keybind"):
        motion.x = -sprint
    else:
        motion.x = -speed