How to make the Attack animation not write over the idle

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

My Idle seems to override my Attack so it only plays the first frame this is my code

extends KinematicBody2D

var state_machine
var run_speed = 200
var attacks = [“attack1”, “attack2”]
var velocity = Vector2.ZERO
var is_attacking

func _ready():
state_machine = $AnimationTree.get(“parameters/playback”)

func _attack():
is_attacking = state_machine.travel(“attack”)

func get_input():
var current = state_machine.get_current_node()
velocity = Vector2.ZERO
if Input.is_action_just_pressed(“attack”):
state_machine.travel(“attack”)
return
is_attacking = true
if Input.is_action_pressed(“jump”):
state_machine.travel(“Jump”)
if Input.is_action_pressed(“left”):
velocity.x -= 1
state_machine.travel(“Run”)
$Sprite.scale.x = -1
if Input.is_action_pressed(“right”):
velocity.x += 1
state_machine.travel(“Run”)
$Sprite.scale.x = 1
if velocity.length() == 0:
state_machine.travel(“Idle”)

func _physics_process(_delta):
get_input()
velocity = velocity.normalized() * run_speed
velocity = move_and_slide(velocity)

Use an action_just_pressed for the attack
and for the animation to play, use another code the same but with action_pressed
What happens is that when you call action_just_pressed, what you do is that only when you press atak, only that instant is reproduced.
and action_pressed is so that if the key is held pressed, it will play the animation if the key is pressed
basically just pressed lasts a frame and pressed lasts until the key is released

I hope it helps you since I do not speak English and it is difficult for me to fully understand your question grettings!

lurgx | 2021-11-06 07:36