Unity: Timeline Character Animation
This article will review how to get character animations working using Timeline in Unity. I will be importing these premade animations from Miximo.com. I will use idle, right turn, and walk backward animations and add a bonus jab. All you have to do to find these animations or ones similar is just search mixamo.com.
I will be using a Ybot Rig. You must set this rig to Humanoid. You can use the free 3rd person armature from the Unity asset store as your default character model as well.
Time to get the animations working starting with the idle animation.
- Create an Empty Game Object, I called it AnimDirector.
- Click the Create button in the Timeline window with the AnimDirector selected
- Save this to your Directors Folder
Idle Animation:
- After importing the Idle animation this is what it will look like
- Again, with this Rig set as Humanoid now Copy the mixamo.com animation and remain it Idle. I had another idle so I named this one Idle0
You will see the Rig change into a default more human-looking character base model.
Cool, so I did this with Right Turn and Walk Backward animations as well.
I went on ahead and set the Ybot as a child of the AnimDirector.
- Drag and drop the Ybot into the AnimDirector Timeline as an Animation Track
- Drop the Idle animation into the Timeline
- The animation is 3 seconds long. I want the idle to be 4 seconds.
- Increase the length of the idle animation to 4 seconds
- Set the Post-Extrapolation to Loop
Punch Animation:
- Drag and drop into the Timeline on the same track as the idle animation
- I will duplicate this to do a double punch and keep it set to Hold
Okay, so you get the idea by now. I put the other animation in as well on this one Timeline track. That would be the right turn and the walk backward animations. Once those were all in it was time to get it to work as smoothly as I could.
Here is what it will look like without any editing. This is not what you will want. You can see there is no real fluidity to it at all as is. It will just snap to the next animation and its start position.
- From Idle to Punching we just needed to do basic ease in from Punching to Idle.
Now as you will see it goes from Idle to a smooth couple of punches instead of snapping to the next animation.
Turn Right Animation:
- Copy Idle0 and put it after the Punches
- make sure the Right Turn animation is now after the second Idle0
Here is the full animation to this point. You will see the problem once we et to walk backward regarding positioning. Other than that the rest is working perfectly.
Walk backward Animation:
You can see I already have the Walk Backward animation as the last animation. Now let's fix the starting position/rotation issue for this animation and get a final result.
- Will ease it into the Right Turn animation a bit
- Take the Time Marker and drag it right up to the point where the right-turn animation is about to go into the walk backward
- Right-Click on Walk Backward and select Match Offsets to Previous Clip
Now, this full animation including the walking back looks much more natural.
To get a little practice let's try a little more.
- Duplicate Right Turn, put it as the last animation for now, and have it ease into walking backward
- Set the Right Turn to Match Offsets to Previous Clip to fix the obvious issue you will see
After matching the offsets the Ybot will now smoothly turn as it should. now let's get it to walk back again.
Walk Back Again
- Duplicate Walk Backward will end up in form of the new Right Turn
- Match Offsets to Previous Clip
- I put another Idle and a final punch. They both required to Match Offsets to Previous Clip
Here is the final result.