Sword attack animation will stop me from moving

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Erto

Hello! Im trying to make it so I can play my sword animation while I jump and move. For some reason i can move and jump initially. But if I press my sword attack I can no longer move or jump. Just play the sword animation. Would appreciate some help!

var canSlash = false

func _ready():
pass

func _process(delta):
var movement = Input.get_action_strength(“ui_right”) - Input.get_action_strength(“ui_left”)
if movement != 0 && canSlash == false:
velocity.x += movement * speed * delta
$anim.flip_h = movement < 0
$anim/anima.play(“WALK”)
elif velocity.x == 0 && velocity.y < 0 && canSlash == false:
$anim/anima.play(“JUMP”)
elif velocity.x == 0 && velocity.y > 30 && canSlash == false:
$anim/anima.play(“FALL”)
elif movement == 0 && canSlash == false:
velocity.x = 0
$anim/anima.play(“IDLE”)

if velocity.y > 350:
	get_tree().reload_current_scene()

	
	
	
if is_on_floor() && Input.is_action_just_pressed("ui_accept") && canSlash == false:
	velocity.y -= jump
	$anim/anima.play("JUMP")
elif velocity.y < 0 && velocity.x != 0 && canSlash == false:
	$anim/anima.play("JUMP")
elif velocity.y > 30 && velocity.x != 0 && canSlash == false:
	$anim/anima.play("FALL")  
if Input.is_action_just_pressed("ui_sword1"):
	canSlash = true
	$anim/anima.play("SWORD1")
	if is_on_floor() && canSlash == true:
		$anim/anima.play("SWORD1")
	elif velocity.y < 0 && velocity.x != 0 && canSlash == true:
		$anim/anima.play("SWORD1")
	elif velocity.y > 0 && velocity.x != 0 && canSlash == true:
		$anim/anima.play("SWORD1")
:bust_in_silhouette: Reply From: Uden

It looks like to me whenever you press the sword attack button you turn canSlash to true which makes you unable to jump or move. Is there a statement anywhere that turns canSlash to false? Maybe when you’re grounded or after the animation plays.

Hi! Thank you for trying to help. i think you mean this .

func _on_anima_animation_finished():
if $anim/anima.animation == "SWORD1":
	canSlash = false

And now I have discovered that there is a error in here:
E 0:00:48.777 emit_signal: Error calling method from signal ‘animation_finished’: ‘KinematicBody2D(KinematicBody2D.gd)::_on_anima_animation_finished’: Method expected 0 arguments, but called with 1…

I think the problem could be that I am using animation player and sprite. The tutorial i based this on was using animated sprite.

Erto | 2023-05-18 21:23

Try connecting the animation_finished signal from animation player to your code. If that doesn’t work (probably because your animation is looping), you could try making a timer based on the animation length that you desire to send a signal to the function instead.

Uden | 2023-05-18 22:14

I have it connected to my code. My animation isnt looping

Erto | 2023-05-19 01:08