MAKING YOUR OWN ANIMATIONS
Last updated
Last updated
Below is a short tutorial for making new animation for characters inside Unity.
Select any one of the character prefabs and go into Prefab Editing mode.
Select Animator
in the Hierarchy
, create a new clip in the Animation window. Then you can start keying your animation.
You should only key on objects under the Animator
object. All the character’s bones are in the Rig
hierarchy.
You can use the Bone Renderer
script of Unity’s Animation Rigging
package (available in Package Manager) for displaying and easy selecting bones in the scene.
Add a Bone Renderer
script to the character and click on the lock button on the top-right corner of the Inspector window.
Right click on Rig
object inside the character hierarchy and select Select Children
.
Drag all the objects selected to the Transforms
list of the Bone Renderer
script.
Some of the Rig objects are just helper objects. For example Rig
, Rig LPlatform
, Rig RPlatform
. You can delete them from the Transforms
list to stop them from being displayed.
As the Bone Renderer
cannot properly display end bone’s length correctly. You can manually and a new object to the end bone and place it at the end position, then drag it to the Transforms
list of the Bone Renderer
to force the end bone to be displayed with a proper length.
When your animation is done, you need to put the clip into the character’s Animator Controller
.
In this case we made a kick animation, so we add a new layer in the Animator
called Kick
, a new trigger parameter call Kick
and setup the animation state as the picture below.
We use an empty state (with no motion clip) as the entry state. When Kick
parameter is triggered, it transits to the Kick
state with the animation clip we just made. When the Kick
animation finish playing, it goes back to the Empty
state.
Then we need to trigger the Kick
parameter with our code. You can put the code anywhere you like. In this case, we put it in the Pixel Character Controller
script.
Then, we are able to trigger the kick animation by the Kick
function or the Kick
button in the Inspector.
The weapon object placed inside Weapon Slot
is syncing its position with Rig Weapon
bone through script in runtime. So, in the editor, the weapon object will not move with the Rig Weapon
bone. This brings inconvenience when making animation.
To solve this, simply drag the weapon object into the Rig Weapon
.
As mentioned above, there are many modifications we may need to do to the character prefab to prepare it for making animation.
So, my suggestion is that you copy the character prefab you want to make animation for and make your modifications to the clone instead of directly to the prefab you are going to use in game.
Animations created in any one of the character prefabs are also compatible in other characters as they share the same rig structure.