Files
godot_test/scripts/3d_godot_robot.gd
2025-08-08 16:36:54 +05:00

37 lines
1.2 KiB
GDScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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