AnimationPlayer changing for 'spamming' action inputs

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jjphung
:warning: Old Version Published before Godot 3 was released.

So my current code for animation player is “laggy” and doesn’t change direction very quickly. How can I change the code so if players do spam the left and right buttons the animation player will respond accordingly? Here is the sprite sheet for reference: Sprite Sheet. My animation player is: .3 seconds with .1 steps and keyframes at 0, 1, 2, 0 for left animation and 3, 4, 5, 3 for right animation

func _fixed_process(delta):
	velocity.y += delta * GRAVITY
	if (Input.is_action_pressed("ui_left")):
		velocity.x = -WALK_SPEED
		if not animPlayer.is_playing():
			sprite.set_frame(0)
			animPlayer.play("walk_left")
	elif (Input.is_action_pressed("ui_right")):
		velocity.x = WALK_SPEED
		if not animPlayer.is_playing():
			sprite.set_frame(4)
			animPlayer.play("walk_right")
		
	else:
		velocity.x = 0

A side comment:
If that is your spritesheet, you can have a single “walk” animation and just flip texture when turning.

eons | 2017-04-13 13:41

:bust_in_silhouette: Reply From: Omicron

You have to check which animation is currently played. (get_current_animation ( ))

If your player is pressing right, while current animation is walk_left, you want to change that !

Also eventually stop the animation, and set it to its starting position when your player doesn’t press any key. (or eventually start an “idle” animation)