add running and crouching

This commit is contained in:
2025-02-13 19:08:08 +10:00
parent 669eed3a1b
commit 0652e0d23b
4 changed files with 27 additions and 2 deletions

View File

@@ -2,6 +2,8 @@ class_name Player
extends CharacterBody3D
const MOVE_SPEED: float = 5
const RUN_SPEED: float = 10
const CROUCH_SPEED: float = 1
const MOVE_ACCELERATION: float = 50
const MOVE_DECELERATION: float = 25
@@ -126,7 +128,15 @@ func _lateral_movement(delta: float) -> void:
var direction := (
(transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
)
var new_velocity := direction * MOVE_SPEED
var speed := MOVE_SPEED
Debugger.text("move_mode", "move", 2)
if Input.is_action_pressed("crouch"):
speed = CROUCH_SPEED
Debugger.text("move_mode", "crouch", 2)
if Input.is_action_pressed("run"):
speed = RUN_SPEED
Debugger.text("move_mode", "run", 2)
var new_velocity := direction * speed
new_velocity.y = velocity.y
velocity = velocity.move_toward(new_velocity, MOVE_ACCELERATION * delta)
else: