Godot Version
`4.4
Question
Is there any way to make the character move with an animation so that when the animation is over, the character has a new position? what I want to do is make a lunging attack. If I use animationplayer that only affects the sprite not the position of the characterbody. I tried setting up a timer to execute a position.x += 500 code after animation ends and that works except right at the end it gets a little glitchy no matter how I try to time it. Anyone know how to do this? I feel like this should be pretty easy to find how to do since its so common in games but I cant find any tutorials or anything on how to do it. Any help much appreciated.
(Google translator)
I’m no expert. I hope someone gives you a better answer than mine.
I think the easy way is to simply add a speed to the character appropriate for the animation being played.
On the other hand, you can also extend your character’s collision, during that animation, so that it covers more distance.
I also think you could move the character from the animation by adding a “call method track” in the AnimationPlayer but this will be difficult to adjust.
Root movement (this is not easy)
In 3D I believe this is called “root motion” and is documented in the Godot documentation. You can search for tutorials on this topic on YouTube. The animation is not created in the same place but rather advances the character. If, for example, you download animations from Mixamo, you can do so on the site or not. By advancing the root bone, you program your character’s movement around it and that advances the collision associated with your character appropriately.
What you achieve with that is precisely what you say. The animations look much better since the character moves with the animation.
It is also true that in cases such as jumping it is said that this is not very convenient because it is not completely precise and when a player jumps he must be very clear about where he is going to end up. Walking or running will be fine, and climbing stairs may be best (I think).
In 2D I haven’t seen any of this, I’m very new, but if you made your frames change your character’s location it would be possible to do it anyway. Of course, the calculation of the movement is done differently.
The links for 3d, which I think are relevant are:
https://docs.godotengine.org/en/stable/tutorials/animation/animation_tree.html#root-motion
https://docs.godotengine.org/en/stable/classes/class_animationmixer.html#class-animationmixer-method-get-root-motion-position