@DarlesLSF said:
Thats helped :+1:
Great! Glad it was of some help.
I have another question now:
First, I hold the directional keys and looks fine. After, when I pressed once the arrow keys, the animation doesnt run, just move staticly. Look:

How can I fix that?
Without looking at the code that moves the character, it is hard to say for sure. If possible, can you post the code for the character?
The issue is most likely that the animation is being called whenever the arrow keys is pressed, without checking to see if the animation is already playing. This causes the first frame of the animation to be played repeatedly, giving the static look.
A simple solution is to check to see if the animation is playing already before changing to it. Something like the following should work:
# When the arrow key(s) are pressed, or whatever happens before
# the animation is changed.
if Input.is_action_pressed("ui_left"):
# Check to see if the the animation playing is not the animation we want to change to
# this way, the code will tell the animation to change to the animation we want, but if it is playing
# the animation we want, then it will not change.
#
# (I am assuming that "andando_esquerda" is the animation you want to use when moving).
if (animation_player_node.current_animation != "andando_esquerda"):
# change the animation!
animation_player_node.play("andando_esquerda")
else:
# the animation we want is playing, so don't do anything.
pass
# Add any other code you want to play when the character is moving here!
That is one way to check whether the animation needs to be changed or not. There are other ways to do it that depending on your project, may be better or worse. Hopefully what I wrote gives the general idea.
Another common case where this can happen is where the animation being played is based on the velocity of the character. When a key is tapped instead of held, this can rapidly change the velocity, causing only the first few frames of animation to be shown (causing the static look).
Finding a solution to this issue is largely dependent on how your game works, how often the velocity is going to change in the game, and other factors that make finding a generic solution to the issue difficult.
One solution is to interpolate the velocity when the player moves, smoothing the changes to velocity and giving the animation more time to play. The downside of this approach is that the player won't instantly start moving, but instead their movement in any direction will be interpolated. Depending on your game, this may or may not work.
The solution I often use is blending the animations together by passing a custom_blend
argument to the play
function in the AnimationPlayer node. By blending in the animations, it smooths the transitions from the idle animation to the moving animation.
This works for 3D animation and bone-based 2D animation, as the key frames in the animation are just different positions, rotations, and/or scales. For frame based 2D animation, I have no idea how blending would work, nor if it would give desirable results.
Hopefully what I wrote above helps in finding a solution to the issue! :smile: