Default animations still playin when not suppose to

Godot Version

4.2.2

Question

Hi! im nearly done with coding my dialogue system, but theres only one thing that annoys me, my default animations still activates when trying to chose an option.

i think the problem is this:

Blockquote
if Input.is_action_just_released(“move_down”):
play_animation(“default_down”)
elif Input.is_action_just_released(“move_up”):
play_animation(“default_up”)
elif Input.is_action_just_released(“move_right”):
play_animation(“default_right”)
elif Input.is_action_just_released(“move_left”):
play_animation(“default_left”)

but i dont know how to make it in other way

the full script:

Blockquote
extends CharacterBody2D

var speed = 150
var run_speed = 230
var is_running = false

@onready var animation = $AnimatedSprite2D

var current_animation = “”

func _ready():
Dialogic.timeline_started.connect(set_physics_process.bind(false))
Dialogic.timeline_started.connect(set_process_input.bind(false))

Dialogic.timeline_ended.connect(set_physics_process.bind(true))
Dialogic.timeline_ended.connect(set_process_input.bind(true))

pass

func _unhandled_input(event):

# Movimiento
velocity.x = Input.get_axis("move_left", "move_right")
velocity.y = Input.get_axis("move_up", "move_down")	

# Animaciones cuando no se mueve
if Input.is_action_just_released("move_down"):
		play_animation("default_down")
elif Input.is_action_just_released("move_up"):
		play_animation("default_up")
elif Input.is_action_just_released("move_right"):
		play_animation("default_right")
elif Input.is_action_just_released("move_left"):
		play_animation("default_left")

func update_animation():
var new_animation = “”

if abs(velocity.x) > abs(velocity.y):
	if velocity.x > 0:
		new_animation = "walk_right"
	else:
		new_animation = "walk_left"
else:
	if velocity.y > 0:
		new_animation = "walk_down"
	else:
		new_animation = "walk_up"

if current_animation != new_animation:
	play_animation(new_animation)

func play_animation(anim_name):
if animation.animation != anim_name:
animation.play(anim_name)
current_animation = anim_name

func _physics_process(delta):

is_running = Input.is_action_pressed("ui_back")
var current_speed = speed
if is_running:
	current_speed = run_speed

if velocity != Vector2.ZERO:
	velocity = velocity.normalized() * current_speed
	move_and_slide()
	update_animation()

func player():
pass

You can add a variable to check if its supposed to play an animation:

var stop_animation


func _unhandled_input(event):
    if stop_animation:
        return

    if Input.is_action_just_released(“move_down”):
        play_animation(“default_down”)
    elif Input.is_action_just_released(“move_up”):
        play_animation(“default_up”)
    elif Input.is_action_just_released(“move_right”):
        play_animation(“default_right”)
    elif Input.is_action_just_released(“move_left”):
        play_animation(“default_left”)
1 Like

thanks!!

1 Like