Загрузка данных


func _physics_process(delta: float) -> void:
	# 1. Гравитация
	if not is_on_floor():
		velocity.y -= gravity * delta

	# 2. Прыжок (Space)
	if Input.is_key_pressed(KEY_SPACE) and is_on_floor():
		velocity.y = JUMP_VELOCITY

	# 3. Обработка Рывка (Shift)
	if Input.is_key_pressed(KEY_SHIFT) and not is_dashing:
		start_dash()

	if is_dashing:
		dash_timer -= delta
		velocity.x = dash_direction.x * DASH_SPEED
		velocity.z = dash_direction.z * DASH_SPEED
		if dash_timer <= 0:
			is_dashing = false
	else:
		# 4. Считывание клавиш WASD
		var input_dir := Vector2.ZERO
		if Input.is_key_pressed(KEY_D): input_dir.x += 1
		if Input.is_key_pressed(KEY_A): input_dir.x -= 1
		if Input.is_key_pressed(KEY_S): input_dir.y += 1
		if Input.is_key_pressed(KEY_W): input_dir.y -= 1
		input_dir = input_dir.normalized()

		var direction := (camera_pivot.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()

		if direction:
			velocity.x = direction.x * SPEED
			velocity.z = direction.z * SPEED
		else:
			velocity.x = move_toward(velocity.x, 0, SPEED)
			velocity.z = move_toward(velocity.z, 0, SPEED)

	move_and_slide()

func start_dash() -> void:
	is_dashing = true
	dash_timer = DASH_DURATION
	
	var input_dir := Vector2.ZERO
	if Input.is_key_pressed(KEY_D): input_dir.x += 1
	if Input.is_key_pressed(KEY_A): input_dir.x -= 1
	if Input.is_key_pressed(KEY_S): input_dir.y += 1
	if Input.is_key_pressed(KEY_W): input_dir.y -= 1
	input_dir = input_dir.normalized()
	
	if input_dir != Vector2.ZERO:
		dash_direction = (camera_pivot.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
	else:
		dash_direction = -camera_pivot.transform.basis.z.normalized()