extends Node3D @export var appearance: CharacterAppearanceProfile = preload( "res://assets/characters/profiles/reference_cat.tres" ) @onready var body_mesh: MeshInstance3D = $Body @onready var head_mesh: MeshInstance3D = $Head @onready var hair_mesh: MeshInstance3D = $Hair @onready var left_arm: MeshInstance3D = $ArmLeft @onready var right_arm: MeshInstance3D = $ArmRight @onready var left_leg: MeshInstance3D = $LegLeft @onready var right_leg: MeshInstance3D = $LegRight var player_body: CharacterBody3D var walk_phase := 0.0 var rest_heights := Vector3(1.05, 1.68, 1.9) var arm_swing := 1.0 func _ready() -> void: player_body = get_parent() as CharacterBody3D AnimalAppearance.apply_to(self, 0, false, appearance) rest_heights = AnimalAppearance.rest_heights(self) arm_swing = get_meta("arm_swing", 1.0) func _process(delta: float) -> void: if player_body == null: return var horizontal_speed := Vector2(player_body.velocity.x, player_body.velocity.z).length() var blend := minf(delta * 10.0, 1.0) if horizontal_speed > 0.1: walk_phase = fmod(walk_phase + delta * horizontal_speed * 3.4, TAU) var swing := sin(walk_phase) left_leg.rotation_degrees.x = lerpf(left_leg.rotation_degrees.x, swing * 30.0, blend) right_leg.rotation_degrees.x = lerpf(right_leg.rotation_degrees.x, -swing * 30.0, blend) left_arm.rotation_degrees.x = lerpf( left_arm.rotation_degrees.x, -swing * 22.0 * arm_swing, blend ) right_arm.rotation_degrees.x = lerpf( right_arm.rotation_degrees.x, swing * 22.0 * arm_swing, blend ) var step_bob := absf(sin(walk_phase * 2.0)) * 0.035 body_mesh.position.y = lerpf(body_mesh.position.y, rest_heights.x + step_bob, blend) head_mesh.position.y = lerpf(head_mesh.position.y, rest_heights.y + step_bob, blend) hair_mesh.position.y = lerpf(hair_mesh.position.y, rest_heights.z + step_bob, blend) return left_leg.rotation_degrees.x = lerpf(left_leg.rotation_degrees.x, 0.0, blend) right_leg.rotation_degrees.x = lerpf(right_leg.rotation_degrees.x, 0.0, blend) left_arm.rotation_degrees.x = lerpf(left_arm.rotation_degrees.x, 0.0, blend) right_arm.rotation_degrees.x = lerpf(right_arm.rotation_degrees.x, 0.0, blend) body_mesh.position.y = lerpf(body_mesh.position.y, rest_heights.x, blend) head_mesh.position.y = lerpf(head_mesh.position.y, rest_heights.y, blend) hair_mesh.position.y = lerpf(hair_mesh.position.y, rest_heights.z, blend)