37 lines
1.2 KiB
GDScript
37 lines
1.2 KiB
GDScript
extends Node3D
|
||
class_name Body
|
||
|
||
const LERP_VELOCITY: float = 0.15
|
||
|
||
@export_category("Objects")
|
||
@export var _character: CharacterBody3D = null
|
||
@export var animation_player: AnimationPlayer = null
|
||
|
||
func animate(velocity: Vector3) -> void:
|
||
if not _character.is_on_floor():
|
||
if velocity.y < 0:
|
||
animation_player.play("fall")
|
||
else:
|
||
animation_player.play("up")
|
||
return
|
||
|
||
# Используем _has_input вместо проверки длины скорости
|
||
if _character._has_input:
|
||
if _character.is_running():
|
||
animation_player.play("run")
|
||
else:
|
||
animation_player.play("walk")
|
||
return
|
||
|
||
# Плавное переключение на 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:
|
||
rotation.y = rotation_y
|