–EDIT–
I’ve decided to animate the velocity directly. This might not be the best way, but it works. I have two variables that my controller script assigns to rigidbody2D.velocity every frame as long as a boolean called ‘animateVelocity’ is set. In the animation clip, I animate animateVelocity to on, then manipulate the rigidbody velocity. Besides the obvious difficulty in animating velocity rather than position, the main drawback is that I have to actually play the game to preview the animation, making tweaking difficult.
Having trouble deciding the best way to animate a character with a RigidBody2D.
The player character has various animations that can be triggered by input which cause a control override and force the character along a particular path (imagine performing an uppercut in a fighting game as an example).
I figured that there are a few methods I could try:
Animate the transform of a child object in the player GameObject to animate the relative position
Animate a variable that changes rigidbody2D.velocity of the player GameObject
The problem I’m seeing with the first method is that it returns to the starting position ( (0,0,0) in the case of said child object) automatically after the animation ends, which is undesirable. What am I missing here? Is there a way to prevent this?
When I consider the second method, I am aware that it will be very difficult to achieve the specific motions that I am imagining for my character. Is there an easier way that I’m not thinking of?
Note: The player will be unable to control the player character and the player character is unaffected by gravity for the duration of these types of animations. Additionally, walls and other colliders will still need to block the RigidBody. I.e. collision physics should still apply during the animations, which is why I considered animating the velocity, the same way the character is made to move in my scripts. I’m also having problems with unpleasant jittering when the character hits a wall during the animation, but one problem at a time I suppose.