martes, 6 de febrero de 2024

Script para godot4.2 un personaje, le cambias la animacion, presionando otra tecla;

 extends Node3D


# Variables para controlar si la animación está activa y el nombre de la animación actual

var is_animating = false

var anim_name = ""


# Called when the node enters the scene tree for the first time.

func _ready():

pass


# Called every frame. 'delta' is the elapsed time since the previous frame.

func _process(delta):

# Reproduce la primera animación al presionar la tecla "M"

if Input.is_action_pressed("ui_up"):

if not is_animating:

$AnimationPlayer.play("Armature|mixamo_com|Layer0")

anim_name = "Armature|mixamo_com|Layer0"

is_animating = true

# Reproduce la segunda animación al presionar la tecla "N"

elif Input.is_action_pressed("ui_down"):

if not is_animating:

$AnimationPlayer.play("otra/otramas")

anim_name = "otra/otramas"

is_animating = true

# Evita repetir la animación mientras se mantiene presionada la tecla

elif is_animating and not Input.is_action_pressed(anim_name):

is_animating = false