# Animations

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FMJSEScU1uJO9s98sj8Cs%2FPola_Auferre_all.png?alt=media&#x26;token=6743b972-f795-4e89-8329-a79c61421e61" alt=""><figcaption><p>Starting Sprite page. Note the lack of 4 directions. The side animation can be flipped in the animator.</p></figcaption></figure>

In the scene, drag one of the sprites. Make sure it is selected before you start creating animations so you can see it in the scene.

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FrvxZzgNj4tRvzfudU3eW%2FSelect%20Sprite%20GameObject%20In%20Scene.png?alt=media&#x26;token=33410179-f09b-4070-a39e-6446d862c6e6" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FCau2366KSKl1APfTlWMy%2FWindow%20for%20Animatino.png?alt=media&#x26;token=7c6a7777-219f-4542-b06b-03d78ede7988" alt=""><figcaption><p>Where to open the "Animation" window.</p></figcaption></figure>

Once the window is open, click "Create" and then save the first animation file. Then, drag and drop the sprites from the project folder and into the timeline. You'll be able to drag multiple at the same time and even scale them all with the blue handles on each side.&#x20;

Note: The last frame needs to have a second copy of it at the end about 10 seconds later so that the animation loops properly.

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FWL2LylSo6p1joAjRnnYs%2FAnimation%2001.png?alt=media&#x26;token=4bca02ad-f424-4ba0-b538-5ad3338fa86d" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2F4MEWyuwmMh7KvXBR2Gic%2FAnimation%2002.png?alt=media&#x26;token=31917ed5-b179-412c-8513-6fa045c3ab89" alt=""><figcaption></figcaption></figure>

In the opposite side animation, simply add the "Sprite Renderer" -> Flip X, and then make sure it only has one key frame and that it is checked. Now, for that entire animation, the sprite is flipped.

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FNajhSWUEvz9yizZE6HTZ%2FAnimation%2003.png?alt=media&#x26;token=9a06a6d1-2507-4686-aa68-a325c5535c7c" alt=""><figcaption></figcaption></figure>

## Animator Component

This is where we can have this one sprite have many different animations and transition seamlessly between them. Open the Animator window.

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FwnxC20W7n5Tuh7Ic7BMC%2FWindow%20for%20Animator.png?alt=media&#x26;token=4d512df4-752e-4a30-85f3-600e88b3e75d" alt=""><figcaption><p>It is right next to the "Animation" window.</p></figcaption></figure>

If the Player Sprite gameObject is selected in the scene view, this is what you should see.

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FXRA8gDkJymjr0SJ652yX%2FWhat%20you%20should%20see%20for%20Animator.png?alt=media&#x26;token=745ca114-7531-4a6d-abd3-8e870ff6a1ec" alt=""><figcaption><p>Animator Window Initial State</p></figcaption></figure>

The orange animation means that is set as the default.

To create a transition, right click on the box, select "Create Transition" and then pull that arrow to the box you want to transition it to. Clicking on the line between the two animations will bring up the Transition details in the "Inspector" panel.

"Has Exit Time" allows you to play a certain animation for a set time before it automatically goes to the next animation.

"Transition Duration" means how long will the transition last before it goes to the next animation. In this use case, we want to transition to happen immediately, so this field is set to 0.&#x20;

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FOpey5VB3THG6dJxF6QXH%2FTransition%20details.png?alt=media&#x26;token=cac5d3eb-e83e-47a7-8b42-ba0dd8f700a4" alt=""><figcaption></figcaption></figure>

To add parameters that will trigger transitions, you can do so in this place.

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2Fm8unpOb4KGw5bVXGg3Zq%2FAnimator%20Click%20on%20Parameters.png?alt=media&#x26;token=36b63ac9-9503-41dd-9224-710de0ad9320" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2F0uVBpQKCD8jvUVQB0FZw%2FSelecting%20a%20Parameter.png?alt=media&#x26;token=37394306-4337-4ac8-8347-f958ed7a180c" alt=""><figcaption></figcaption></figure>

## Blend Tree

For this use case, individually setting transitions between all states is going to be messy. We're going to use a Blend Tree. Delete all the other animation blocks except for the default. Right click on an empty space in the animator window, click "Create State," and select "From New Blend Tree."

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FHXSvE4LUDdHkfRokE5PW%2FNew%20Blend%20Tree.png?alt=media&#x26;token=01bae908-7e8a-4b28-960e-ddc3645e4f35" alt=""><figcaption></figcaption></figure>

Double-clicking on the blend tree box will let you go into it.

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FDJUP9wmW2uTsrJRHfCsY%2FBlendTree1.png?alt=media&#x26;token=f57736ba-4bc8-499a-8bad-13510993c676" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2F8XekiOenZy5NsLvpg5AB%2FBlendTree2.png?alt=media&#x26;token=89b609cf-5943-4839-ada8-e72e6455b356" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FCVySsTz5UKRA3yn8Lkav%2FBlendTree3.png?alt=media&#x26;token=c24beccd-81ed-4b23-93f6-a4a585017e2d" alt=""><figcaption><p>Remember to change the second parameter.</p></figcaption></figure>

Very useful button for animation. Note the circle.

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FFQGaZNgupieAtBkbWZjQ%2FBlendTree4.png?alt=media&#x26;token=d31666f5-de60-40bd-afcc-cefd723ed71d" alt=""><figcaption></figcaption></figure>

This opens the animations library.

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2F0pvB4YTD3qnxJpZc4U3d%2FBlendTree4b.png?alt=media&#x26;token=b13c838a-366c-4ec3-86fd-782ba0d4c72d" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FmOKtYP1G2GauWt6mrQau%2FBlendTree_Walk1.png?alt=media&#x26;token=03226931-e624-472e-902e-7c25f1da6bb3" alt=""><figcaption></figcaption></figure>

Note: Make sure that there is an "Animator" component on the gameObject holding the sprites and that it has the correct animator controller asset.

Create a second blend tree for the idle animation. Add two more floats to parameters.

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FbdzZXIGM0WLaHXnHAlTW%2FFacingRightDirection.png?alt=media&#x26;token=636199ac-3d2b-4a11-af68-4bb86c2aadf8" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2Fj2soEuvuDiweCcEKGijr%2FBlendTree_Idle.png?alt=media&#x26;token=2c3e0ca3-541a-4c1a-8546-a014616adf1a" alt=""><figcaption></figcaption></figure>

Set the animation default to the idle blend tree. You're going to create four individual transitions from idle to movement, and in each condition, set one of the variables.&#x20;

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FDNU5RkM97Zx1fyXaSSTW%2FFour%20Transitions.png?alt=media&#x26;token=43fd4ae6-6a95-4259-979a-ebd2f52f0dca" alt=""><figcaption></figcaption></figure>

Greater than 0.1, Less than -0.1; moveX, moveY

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FhtJRWnq6ZcQeCNOb6OLC%2Ftransition%20condition.png?alt=media&#x26;token=e58c9e3b-9d0c-4731-9402-543b6c10a87e" alt=""><figcaption></figcaption></figure>

Transitioning back to idle from movement requires only one transition.

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2Fv4uz7XlTI77sdOArPnZM%2FTransition%20back.png?alt=media&#x26;token=91440a0d-8090-4b1c-8e5d-ebbacb5cd9e3" alt=""><figcaption></figcaption></figure>
