# MAKING YOUR OWN ANIMATIONS

### Overview

Below is a short tutorial for making new animation for characters inside Unity.

### Basic

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.

<figure><img src="https://2697269646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVAsWZLJR6xuMkfJM3gAU%2Fuploads%2FSMGZYAXoqvlWtCR7UUWb%2Fanimation_basic.png?alt=media&#x26;token=b41a9ab9-3f96-41d8-a127-d09275240c38" alt="" width="563"><figcaption></figcaption></figure>

You should only key on objects under the `Animator` object. All the character’s bones are in the `Rig` hierarchy.

### Bone Display

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.

<div><figure><img src="https://2697269646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVAsWZLJR6xuMkfJM3gAU%2Fuploads%2FmKXrIszm2IeYJCEZprtU%2Fbone_display_01.png?alt=media&#x26;token=63d82c57-2440-460a-8dea-197113547de8" alt="" width="172"><figcaption></figcaption></figure> <figure><img src="https://2697269646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVAsWZLJR6xuMkfJM3gAU%2Fuploads%2F5DMI9HsnXzB6k3ae2mHb%2Fbone_display_02.png?alt=media&#x26;token=228a6487-194b-4d4a-b958-1efa5abdcbff" alt="" width="210"><figcaption></figcaption></figure></div>

* 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.

<figure><img src="https://2697269646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVAsWZLJR6xuMkfJM3gAU%2Fuploads%2FcUllcJxCEPSZz8KUBQ7P%2Fbone_display_03.png?alt=media&#x26;token=b99847d5-319d-4c26-89bf-6776c3220018" alt="" width="375"><figcaption></figcaption></figure>

### Animator Setup

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.

<div><figure><img src="https://2697269646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVAsWZLJR6xuMkfJM3gAU%2Fuploads%2FKaG2zC1kZUuk8w6tOsN0%2Fanimator_setup_01.png?alt=media&#x26;token=6477f3a1-93f2-4415-9a7d-a84f9d17200f" alt=""><figcaption></figcaption></figure> <figure><img src="https://2697269646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVAsWZLJR6xuMkfJM3gAU%2Fuploads%2FbSEukB6zBwD9EusEC2kl%2Fanimator_setup_02.png?alt=media&#x26;token=1bfb4109-1c39-4f74-ab4d-a867835dd6ed" alt=""><figcaption></figcaption></figure></div>

### Scripting

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.

<div><figure><img src="https://2697269646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVAsWZLJR6xuMkfJM3gAU%2Fuploads%2Faq28tS4BvqAn2dy5KD1D%2Fanimation_scripting_01.png?alt=media&#x26;token=520c9216-810f-4b6e-bd40-adcf3042fa67" alt=""><figcaption></figcaption></figure> <figure><img src="https://2697269646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVAsWZLJR6xuMkfJM3gAU%2Fuploads%2Fx7jsW0IkNe2qKuaz1KlV%2Fanimation_scripting_02.png?alt=media&#x26;token=2047d74e-4522-4b6a-8030-f83520e5d4c2" alt=""><figcaption></figcaption></figure></div>

### Create a Specific Prefab for Making Animation

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.
