Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | jjphung | |
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