add: smooth move

This commit is contained in:
aurinex
2025-08-08 16:36:54 +05:00
parent b7ccc4e3d3
commit 5145bdfa9e
6 changed files with 137 additions and 47 deletions

View File

@ -7,22 +7,29 @@ const LERP_VELOCITY: float = 0.15
@export var _character: CharacterBody3D = null
@export var animation_player: AnimationPlayer = null
func animate(_velocity: Vector3) -> void:
func animate(velocity: Vector3) -> void:
if not _character.is_on_floor():
if _velocity.y < 0:
if velocity.y < 0:
animation_player.play("fall")
else:
animation_player.play("up")
return
if _velocity.length() > 0.1: # Если есть движение
# Используем _has_input вместо проверки длины скорости
if _character._has_input:
if _character.is_running():
animation_player.play("run") # Спринт
animation_player.play("run")
else:
animation_player.play("walk") # Обычная ходьба
animation_player.play("walk")
return
animation_player.play("idle") # Бездействие
# Плавное переключение на idle при инерции
if velocity.length() > 0.5: # Небольшой порог для плавного перехода
var current_anim = animation_player.current_animation
if current_anim != "walk" and current_anim != "run":
animation_player.play("walk", 0.1) # Плавный переход с blend_time 0.1 сек
else:
animation_player.play("idle", 0.2) # Плавный переход на idle
@rpc("any_peer", "reliable")
func sync_player_rotation(rotation_y: float) -> void: