Godot Version
4.0
Question
I am considering to implement a 2d platformer charcter including set of animations; would be better thinking about state machine or animatedsprite2d item??
4.0
I am considering to implement a 2d platformer charcter including set of animations; would be better thinking about state machine or animatedsprite2d item??
i was going to implement function to implement attack skill:
func attacking(isAttacking):
if isAttacking == true and is_on_floor():
print('on floor and attacking !!')
if not anim_Sprite2D.is_playing():
print('NOT playing!!!')
anim_Sprite2D.play("ATT")
but when tryng the animation by plaing the game, It just show only the first frame of ATT animation…
It would be helpful to provide what is printed in the output.
the ouptut is very long…I cannot copy it and paste because is long too much…
Does it keep printing 'on floor and attacking !!'
? Does it keep printing 'NOT playing!!!'
? Does it ever print 'NOT playing!!!'
? How did you set up the animation ATT
? Do you have any errors in the debugger? Without additional information, it will be hard to pinpoint the problem.
A state machine is usually a safe bet for handling animation. For the state machine, check when the character is attacking, then play that animation.
examining the output both ‘on floor and attacking !!’ and ‘NOT playing!!!’ are printed several times…
If I understand correctly, 'NOT playing!!!'
should print only once. Is something stopping the animation? Where else do you use anim_Sprite2D
?
you have to know I use that for call the rigth animation when the player move for doing it.. I mean, for instance within the script you can also finding the following code:
if facing == true:
anim_Sprite2D.play("walk_left")
else:
anim_Sprite2D.play("walk_right")
at the beginning of the script I declared the vatiable:
@export var anim_Sprite2D: AnimatedSprite2D
Do other animations play correctly (walk_left
and walk_right
)?
I am workong in a 2d platformer and all characters (player and enemies) are done using state machine, I find it easier to manipulate and maintain. And play the animation in correct state, as said by @ertain