martes, 24 de junio de 2025

GDScript 3 animaciones turnandose cada 5 segundos automaticamente en el mismo personaje; Godot 4.4;

 extends Node3D


@onready var animation_player = $AnimationPlayer

var animations = ["CAE", "POLI", "COJO"]

var current_animation_index = 0

var time_since_last_animation = 0.0

const ANIMATION_CHANGE_INTERVAL = 5.0


func _ready() -> void:

# Start with the first animation

animation_player.play(animations[current_animation_index])

pass

func _process(delta: float) -> void:

time_since_last_animation += delta


if time_since_last_animation >= ANIMATION_CHANGE_INTERVAL:

time_since_last_animation = 0.0

# Move to the next animation

current_animation_index = (current_animation_index + 1) % animations.size()

animation_player.play(animations[current_animation_index])

pass

GDScript en Godot 4.4 fundamental para utilizar las animaciones pasadas de mixamo a blender y de hay a Godot 4.4;

 extends Node3D


var animacion_actual = "RELAX"


func _ready():

$AnimationPlayer.play(animacion_actual)


func _physics_process(delta):

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("RETUERCE") or \

   Input.is_action_pressed("ANDAALANTECONW") or \

   Input.is_action_pressed("ANDAATRASCONS") or \

   Input.is_action_pressed("SALTAYANDA") or \

   Input.is_action_pressed("BOBLEPUÑETAZO") or \

   Input.is_action_pressed("PATADAMEDIA") or \

   Input.is_action_pressed("RELAX") 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 != "3":

$AnimationPlayer.play("3")

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

animacion_actual = "3"


# Animación de ATRABESAR

elif Input.is_action_pressed("mouse_right") or Input.is_action_pressed("RETUERCE"):

if animacion_actual != "DOBLEPUÑETAZO":

$AnimationPlayer.play("DOBLEPUÑETAZO")

animacion_actual = "DOBLEPUÑETAZO"


# 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 != "ANDARES":

$AnimationPlayer.play("ANDARES")

animacion_actual = "ANDARES"

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

if animacion_actual != "ANDARES":

$AnimationPlayer.play("ANDARES")

animacion_actual = "ANDARES"

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

if animacion_actual != "WALTER":

$AnimationPlayer.play("WALTER")

animacion_actual = "WALTER"

elif Input.is_action_pressed("DOBLEPUÑETAZO") or Input.is_action_pressed("E") or Input.is_action_pressed("E"):

if animacion_actual != "DOBLEPUÑETAZO":

$AnimationPlayer.play("DOBLEPUÑETAZO")

animacion_actual = "DOBLEPUÑETAZO"


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

if animacion_actual != "PATADAMEDIA":

$AnimationPlayer.play("PATADAMEDIA")

animacion_actual = "PATADAMEDIA"




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

if animacion_actual != "3":

$AnimationPlayer.play("3")

animacion_actual = "3"

#if Input.is_action_just_pressed("ui_accept") and is_on_floor():

elif Input.is_action_just_pressed("SALTAYANDA") or Input.is_action_pressed("A") or Input.is_action_pressed("D"):

if animacion_actual != "WALTER":

$AnimationPlayer.play("WALTER")

animacion_actual = "WALTER"


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

elif not alguna_tecla_pulsada:

if animacion_actual != "RELAX":

$AnimationPlayer.play("RELAX")

animacion_actual = "RELAX"

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

if animacion_actual != "RELAX":

$AnimationPlayer.play("RELAX")

animacion_actual = "RELAX"








Dos formas de instanciar disparos con Godot 4.4 con el boton izquierdo del raton;

 extends Area3D


var Bullet = preload("res://PROTAGONISTA/area_3dPROLLECTIL.tscn")


func _input(event):

if event is InputEventMouseButton:

if event.button_index == 1 and event.pressed:

# Retrasar la instanciación del proyectil

await get_tree().create_timer(0.5).timeout

var bullet = Bullet.instantiate()

add_child(bullet)

-------------------------------------------------------------------------------------------------------------

Explicacion : retrasa el disparo 0.5 segundos DESPUES de pulsar el boton del mouse.

---------------------------------------------------------------------------------------------------------------

extends Area3D


var Bullet = preload("res://PROTAGONISTA/area_3dPROLLECTIL.tscn")

var can_fire = true


func _input(event):

if event is InputEventMouseButton:

if event.button_index == 1 and event.pressed:

if can_fire:

can_fire = false

var bullet = Bullet.instantiate()

add_child(bullet)

await get_tree().create_timer(0.5).timeout

can_fire = true


-------------------------------------------------------------------------------------------------------------

Explicacion : retrasa el disparo 0.5 segundos ENTRE DISPARO Y DISPARO al pulsar boton del mouse.

---------------------------------------------------------------------------------------------------------------