jueves, 11 de septiembre de 2025

Animar personaje en godot 4.4. "RELAJO""CAMINA""BOMBAMANO""CORRECACA";

 extends Node3D


var animacion_actual = "RELAJO"


func _ready():

$AnimationPlayer.play(animacion_actual)


func _physics_process(delta):


# NUEVO CÓDIGO: Salir del juego al presionar la tecla Escape

if Input.is_action_just_pressed("ui_cancel"):

get_tree().quit()

var alguna_tecla_pulsada = false



# Comprobamos si alguna de las acciones está siendo presionada

if Input.is_action_pressed("achazo") or \

   Input.is_action_pressed("mouse_left") or \

   Input.is_action_pressed("mouse_right") or \

   Input.is_action_pressed("DESDEABAJOPUÑETASO") or \

   Input.is_action_pressed("ANDAALANTECONW") or \

   Input.is_action_pressed("ANDAATRASCONS") or \

   Input.is_action_pressed("DESDEABAJOPUÑETASO") or \

   Input.is_action_pressed("DESDEABAJOPUÑETASO") or \

   Input.is_action_pressed("CORRECACA") or \

   Input.is_action_pressed("PATADAMEDIA") or \

   Input.is_action_pressed("DESDEABAJOPUÑETASO") or \

   Input.is_action_pressed("ui_accept") or \

   Input.is_action_pressed("A") or \

   Input.is_action_pressed("D"):

alguna_tecla_pulsada = true


# Animación de ESPADAZO

if Input.is_action_pressed("achazo") or Input.is_action_pressed("mouse_left"):

if animacion_actual != "BOMBAMANO":

$AnimationPlayer.play("BOMBAMANO")

#$AnimationPlayer/AudioStreamPlayer3D.play("MakeHuman default skeleton|ESPADAZO")

animacion_actual = "BOMBAMANO"


# Animación de ATRABESAR

elif Input.is_action_pressed("mouse_right") or Input.is_action_pressed("DESDEABAJOPUÑETASO"):

if animacion_actual != "BOMBAMANO":

$AnimationPlayer.play("BOMBAMANO")

animacion_actual = "BOMBAMANO"


# Animación de ANDAR

elif Input.is_action_pressed("ANDAALANTECONW") or Input.is_action_pressed("A") or Input.is_action_pressed("D"):

if animacion_actual != "CAMINA":

$AnimationPlayer.play("CAMINA")

animacion_actual = "CAMINA"

elif Input.is_action_pressed("ANDAATRASCONS") or Input.is_action_pressed("A") or Input.is_action_pressed("D"):

if animacion_actual != "CAMINA":

$AnimationPlayer.play("CAMINA")

animacion_actual = "CAMINA"

elif Input.is_action_pressed("PUÑETAZO") or Input.is_action_pressed("A") or Input.is_action_pressed("D"):

if animacion_actual != "CAMINA":

$AnimationPlayer.play("CAMINA")

animacion_actual = "CAMINA"

elif Input.is_action_pressed("CORRECACA") or Input.is_action_pressed("E") or Input.is_action_pressed("E"):

if animacion_actual != "CORRECACA":

$AnimationPlayer.play("CORRECACA")

animacion_actual = "CORRECACA"


elif Input.is_action_pressed("PATADAMEDIA") or Input.is_action_pressed("R") or Input.is_action_pressed("R"):

if animacion_actual != "BOMBAMANO":

$AnimationPlayer.play("BOMBAMANO")

animacion_actual = "BOMBAMANO"




elif Input.is_action_pressed("ui_accept") or Input.is_action_pressed("A") or Input.is_action_pressed("D"):

if animacion_actual != "CAMINA":

$AnimationPlayer.play("CAMINA")

animacion_actual = "CAMINA"


elif Input.is_action_just_pressed("PUÑETAZO") or Input.is_action_pressed("A") or Input.is_action_pressed("D"):

if animacion_actual != "CAMINA":

$AnimationPlayer.play("CAMINA")

animacion_actual = "CAMINA"



# Si no se presiona ninguna tecla, volvemos a la animación de descanso

elif not alguna_tecla_pulsada:

if animacion_actual != "RELAJO":

$AnimationPlayer.play("RELAJO")

animacion_actual = "RELAJO"

elif Input.is_action_pressed("achazo") or Input.is_action_pressed("A") or Input.is_action_pressed("D"):

if animacion_actual != "CAMINA":

$AnimationPlayer.play("CAMINA")

animacion_actual = "CAMINA"