Does anyone know how to make a sprint?

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

You’re not calling the sprint() function anywhere!

Try calling it inside either _physics_process() or player_movement()

1 Like

Thanks, it worked!

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.