domingo, 10 de mayo de 2026

GDScript para enlazar varias animaciones para Godot 4.6.2;

 extends Node3D


# @export para ajustar qué tan "fuerte" afecta el slider desde el Inspector

@export var multiplicador_suavidad: float = 1.0


var lista_animaciones = [

"Game_engineHOMBRE|Game_engineHOMBREAction",

"Game_engineHOMBRE|Game_engineMUJERAction",

"Game_engineMUJER|Game_engineHOMBREAction",

"Game_engineMUJER|Game_engineMUJERAction"

]


var indice = 0


func _ready() -> void:

# 1. Conectamos señales

$AnimationPlayer.animation_finished.connect(_al_terminar_animacion)

$Node/CanvasLayer/HSlider.value_changed.connect(_on_slider_speed_changed)

# 2. Ajuste inicial de velocidad y sonido

var valor_inicial = $Node/CanvasLayer/HSlider.value * multiplicador_suavidad

$AnimationPlayer.speed_scale = valor_inicial

# Si el sonido está en esta ruta, lo ajustamos al arrancar

if has_node("Node/CanvasLayer/AudioStreamPlayer3D"):

$Node/CanvasLayer/AudioStreamPlayer3D.pitch_scale = valor_inicial

$Node/CanvasLayer/AudioStreamPlayer3D.play()

reproducir_siguiente()


func reproducir_siguiente():

if indice < lista_animaciones.size():

$AnimationPlayer.play(lista_animaciones[indice])

indice += 1

else:

indice = 0

reproducir_siguiente()


func _al_terminar_animacion(nombre_anim):

reproducir_siguiente()


func _on_slider_speed_changed(valor: float):

var nueva_velocidad = valor * multiplicador_suavidad

# Cambia la velocidad de la animación

$AnimationPlayer.speed_scale = nueva_velocidad

# Cambia el tono/velocidad del sonido

if has_node("Node/CanvasLayer/AudioStreamPlayer3D"):

$AudioStreamPlayer3D.pitch_scale = nueva_velocidad


func _input(event):

if event.is_action_pressed("ui_cancel"):

get_tree().quit()