add running and crouching
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user