0 votes

I'm trying to make a running animation to play at 8 directions but it seems to restart the animation at each direction change, I want it to continue from where it left. I'm using spritesheets and AnimationPlayer for animation. How can I manage this?

in Engine by (38 points)
edited by

All your animations have the same ammount of trames? could you share your current code where you manage animation changes?

func animation_loops():
if direction <= 15 and direction >= -15:
    animation_direction = "E"
    right_arm.set_z_index(1)
    left_arm.set_z_index(-1)
    weapon1h.set_z_index(-1)
elif direction <= 60 and direction >= 15:
    animation_direction = "SE"
    right_arm.set_z_index(1)
    left_arm.set_z_index(-1)
    weapon1h.set_z_index(-1)
elif direction <= 120 and direction >= 60:
    animation_direction = "S"
    right_arm.set_z_index(0)
    left_arm.set_z_index(0)
    weapon1h.set_z_index(-1)
elif direction <= 165 and direction >= 120:
    animation_direction = "SW"
    right_arm.set_z_index(-1)
    left_arm.set_z_index(0)
    weapon1h.set_z_index(-1)
elif direction <= -15 and direction >= -60:
    animation_direction = "NE"
    right_arm.set_z_index(1)
    left_arm.set_z_index(-1)
    weapon1h.set_z_index(-1)
elif direction <= -60 and direction >= -120:
    animation_direction = "N"
    right_arm.set_z_index(0)
    left_arm.set_z_index(0)
    weapon1h.set_z_index(-1)
elif direction <= -120 and direction >= -165:
    animation_direction = "NW"
    right_arm.set_z_index(-1)
    left_arm.set_z_index(0)
    weapon1h.set_z_index(-1)
elif direction <= -165 or direction >= 165:
    animation_direction = "W"
    right_arm.set_z_index(-1)
    left_arm.set_z_index(0)
    weapon1h.set_z_index(0)

if idle_state == true:
    animation_mode = "Idle"
    anim_player.playback_speed = 1
else:
    animation_mode = "Run"
    anim_player.playback_speed = 2

animation = animation_mode + "_" + animation_direction
anim_player.play(animation)

Currently I have an idle and a running animation my idle is 8 frames long and running is 16 frames long.

1 Answer

+1 vote
Best answer

You can use current_animation_position to look for the current animation time, and then seek after changing the animation, to put the animation in that frame... something like this:

var frame = anim_player.current_animation_position
animation = animation_mode + "_" + animation_direction
anim_player.current_animation = animation
anim_player.seek(frame)

However, this will work as long as your animations are the same length... if not, you should check before what animation are you changing to, and perhaps apply another rule, although I guess that when you change from run to idle, is ok that idle starts from zero, right?

by (3,505 points)
selected by

Yes this worked, thank you so much! But there is still a problem which you mentioned where changing from run to idle there is a delay, how can i fix it?

If you are ok that when changing from different animation_mode (i mean, from run to idle or from idel to run) the new animation starts from 0, then you could check that if new mode is not the same as current one, just start from zero

var frame = 0
if animation_mode in animation:
    frame = anim_player.current_animation_position
animation = animation_mode + "_" + animation_direction
anim_player.current_animation = animation
anim_player.seek(frame)

Oh now I see your point, I will try that thank you!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.