Animation using Timeline: Road to RealTime part 2
Click here if you want to watch the previous part
Adding animation to characters
Setting a root position for animation
It is a good idea to create an empty game object called RootPosition because it can be used as a reference for a group of characters when animating them
After creating it, set its position as desired and drag and drop the Shanks’ game object into it as its child
- Create a new Animation track
- Select the AnimMaster_Sequence game object and drag and drop the Shanks’ game object into Timeline
- Select Add Animation track
- Choose the HumanoidIdle animation
- Place the new animation clip at the beginning of the Timeline
Press play in Timeline
Nothing happens. Why?
Select the Shanks’ game object in the hierarchy
It shows a new Animator with Controller and Avatar values empty
If you search the HumanoidIdle animation in the project window, click on edit in the inspector
And later on Rig, it will show this
It requires an Avatar, but as we saw before, the game object doesn’t have one
The game object that we selected is a parent game object.
It allows you to set its Transform values, but it didn’t have anything else.
The Animator was added when it was dragged into the Timeline
So, let’s remove its Animator component and search in the children game objects
As you can see, the Shanks_Basic game object has the required Avatar
Adding animations to characters in Timeline
- Select the AnimMaster_Sequence game object in the hierarchy
- Remove the previous Shanks Animator that it contains
- Drag and drop the Shanks_Basic game object into the Timeline
- Select Add Animation track
- Add a new animation from clip. Select HumanoidIdle
- Place the animation clip at the beginning of the Timeline
Press play in the Timeline
It’s working fine. Awesome!
Now select another animation (cyan triangle) from the project folder and add it next to the actual one. I’ll select HumanoidRun
Continuous and looping animation
To make the character run continuously, select the Run animation clip and select the Continue option in Post-Extrapolate.
For looping the animation (to control how many times I want the animation to be executed), select Hold in Post-Extrapolate, click on the animation and drag it to the right
Now you can control how many times you want the animation to be played
Right now, the character will play the Idle animation and suddenly will run.
To fix that (to blend both animations) select the Run animation and drag it a bit into the Idle one.
Animation Transform offset
Currently, the animations are played in a starting position (0,0,0)
If we add an animation after running
To fix that, right click on the last animation and select Match Offsets to previous clip
It is to use the same animations for several characters
These are the new current animations
- Drag and drop some other characters to the hierarchy
- Select the AninMaster_Sequence game object
- One by one, select the child that contains the Animator (_Basic) component and drag and drop it into the Timeline. Select Add Animation Track
Copy all the animations in the Shanks’ timeline animation track and paste them into the other characters animation track
Hope you liked this blog!