28 lines
701 B
GDScript
28 lines
701 B
GDScript
extends CharacterBody3D
|
|
const BASE_STAMINA = 50
|
|
const BASE_SPEED = 4
|
|
const SPRINT_MULT = 1.6
|
|
const STAMINA_COST = 15
|
|
const STAMINA_RECOVER = 10
|
|
|
|
|
|
var stamina: float = BASE_STAMINA
|
|
|
|
func _process(delta: float) -> void:
|
|
$StaminaLabel.text = str(int(stamina))
|
|
|
|
var dir = Input.get_vector("player_move_left", "player_move_right", "player_move_up", "player_move_down")
|
|
|
|
var speed: float = BASE_SPEED
|
|
|
|
if Input.is_action_pressed("player_sprint") and stamina > 0:
|
|
stamina -= STAMINA_COST * delta
|
|
speed *= SPRINT_MULT
|
|
elif stamina <= BASE_STAMINA:
|
|
stamina += STAMINA_RECOVER * delta
|
|
|
|
self.velocity = Vector3(dir.x * speed, 0, dir.y * speed)
|
|
print(str(self.velocity))
|
|
|
|
self.move_and_slide()
|