1
\$\begingroup\$

I am trying to implement an attack animation that should end up in moving the player by some distance. The animation would be something like this:

enter image description here

As you can see the position of the player should be different by the end of the animation, but I am not sure how to make it so. I tried to use root motion, however even if in the animator component i set "Apply root motion" to true, when I click on the animation itself, there is no option to use root motion, perhaps is it due to the fact that the animation is obtained from a spritesheet and not from a rigging software like Spine or DragonBones? Anyway, is there another way to update, either by scripting or throught the animation window, the character's position after the animation?

\$\endgroup\$
1
\$\begingroup\$

Yes, the "apply root motion" flag requires a rigged 3d character model to work.

But the nice thing about the Unity animation system is that you can use it to animate almost any numeric public property of almost any component, including the Transform.

When you are editing the timeline of your Animation with the player game object selected, you can add the Transform as a property and create a curve for the Position.x.

enter image description here

However, I would really recommend you to edit the spritesheet and keep the character centered in the center of the animation cell during every frame. This gives you far more flexibility because you can easily tweak the range of that attack motion in the Unity editor. If your game is an action-oriented game, then the exact distance the character travels when performing that attack is relevant for gameplay. That means it's something you might want to experiment with and iterate on quickly. And then there is also the issue with making sure the collider is where the player would expect it to be during every animation frame. If the character moves around in a sprite which is far larger than itself, then that's quite tedious to get right.

\$\endgroup\$
  • \$\begingroup\$ Thank you very much for the heads up, you probably saved me from a lot of headaches, however, now I am facing another problem: using the animation curves really gives more freedom in how you can tune the displacement, however, if I add the transform.position property A) my character does not move anymore, even if the animations are correctly showing up. I think it is due to the fact that I use rb2d.MovePosition to move my player (?) B) the position change during the animation, but goes back to the starting place once it ends. Do you have any other wonderful suggestions by any chance? - \$\endgroup\$ – FSic Jun 3 at 21:47
  • \$\begingroup\$ I think that I will elaborate the problems in the comment in another question, given that technically you answered to this one. \$\endgroup\$ – FSic Jun 4 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.