Godot Version
4.2
Question
I’m trying to make a sprint for a game, but my code does not work, can anyone explain what wrong with it?
extends CharacterBody2D
var speed = 100
func _physics_process(delta):
player_movement(delta)
look_at(get_global_mouse_position())
func player_movement(delta):
if Input.is_action_pressed("R"):
velocity.x = speed
velocity.y = 0
elif Input.is_action_pressed("L"):
velocity.x = -speed
velocity.y = 0
elif Input.is_action_pressed("D"):
velocity.y = speed
velocity.x = 0
elif Input.is_action_pressed("U"):
velocity.y = -speed
velocity.x = 0
else:
velocity.y = 0
velocity.x = 0
move_and_slide()
func sprint():
if Input.is_action_pressed("sprint"):
speed = 150