extends CharacterBody3D
@export var SPEED: float = 12.0
@export var DASH_SPEED: float = 28.0
@export var ROTATION_SPEED: float = 3.0
@export var GRAVITY: float = 20.0
var is_dashing: bool = false
var dash_timer: float = 0.0
var dash_duration: float = 0.15
func _physics_process(delta: float) -> void:
# 1. Гравитация
if not is_on_floor():
velocity.y -= GRAVITY * delta
# 2. Поворот (A/D или Стрелки Влево/Вправо)
var rotate_input: float = 0.0
if Input.is_key_pressed(KEY_A) or Input.is_action_pressed("ui_left"):
rotate_input += 1.0
if Input.is_key_pressed(KEY_D) or Input.is_action_pressed("ui_right"):
rotate_input -= 1.0
rotate_y(rotate_input * ROTATION_SPEED * delta)
# 3. Рывок (Shift)
if Input.is_key_pressed(KEY_SHIFT):
if not is_dashing:
is_dashing = true
dash_timer = dash_duration
if is_dashing:
dash_timer -= delta
if dash_timer <= 0:
is_dashing = false
# 4. Движение вперед / назад (W/S или Стрелки Вверх/Вниз)
var move_input: float = 0.0
if Input.is_key_pressed(KEY_W) or Input.is_action_pressed("ui_up"):
move_input -= 1.0 # В 3D Godot «вперед» — это -Z
if Input.is_key_pressed(KEY_S) or Input.is_action_pressed("ui_down"):
move_input += 1.0 # Назад — это +Z
var current_speed = DASH_SPEED if is_dashing else SPEED
# Направление с учетом поворота персонажа
var direction = (transform.basis * Vector3(0, 0, move_input)).normalized()
if move_input != 0.0:
velocity.x = direction.x * current_speed
velocity.z = direction.z * current_speed
else:
velocity.x = move_toward(velocity.x, 0, current_speed)
velocity.z = move_toward(velocity.z, 0, current_speed)
move_and_slide()