# Animal Controller

## **Main Principles**

\
**Animal Controller(AC)** is an animation framework controller, root-motion or In Place, for any creature or HUMANOID character. It uses Rigidbody to interact with the physic world and the Animator to play animations.

AC uses **States,** **Modes, and Stances** to play Animations on the animator.&#x20;

### States

**States** are animations that do not overlap each other. For example, the animal cannot be running and jumping at the same time, or flying and swimming.&#x20;

These animations also require some internal logic to work.&#x20;

For walking, the animal requires to be aligned to the ground. For swimming, the animal requires to be aligned to the surface of the water. For Falling, the animal requires gravity to be applied.

### Modes

Modes on the other hand are set of Animations called ***Abilities,*** that can be played on top of the **State** animations. For example, the animal can Attack while running, Dodge while flying, Receive Damage while falling, etc.

In most cases, these animations do not require any specific logic to be applied, but if they need any custom logic: a Mode Modifier can be applied to change some of the effects on the Mode animations.

### Stances

Stances are variations of the State animations. For example. The locomotion animations (Walking, Running) can be played in different ways. The character can walk differently if the animal is hurt, or if is crouching/sneaking or standing on 2 legs.  He is still on the Locomotion State but in a different stance.

## Main Components

The Animal Controller needs an [Animator ](https://docs.unity3d.com/Manual/class-Animator.html)and a [RigidBody ](https://docs.unity3d.com/Manual/class-Rigidbody.html)to work. These two components need to be at the same hierarchy level as the Animal Script.

### **Animator Component**

{% hint style="warning" %}
&#x20;Since we are using the [RigidBody](https://docs.unity3d.com/Manual/class-Rigidbody.html) component, the **Update Mode** is recommended to be set to **Animate Physics**.
{% endhint %}

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2Femuotj7PQv5b8IfO89MD%2Fimage.png?alt=media\&token=538bc844-ece6-4742-9c26-847a81b59634)

### **Rigid Body**

The RigidBody component allows the animal to interact with other rigid and static objects on the scene.

* The rotations will be handled by the Animal component so, by code, all the rotations will be frozen:

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FPTa1uOpBsD6jvfiCGfBg%2Fimage.png?alt=media\&token=831c3dc9-0748-47de-aab4-8e9820b13e91)

### Colliders

{% hint style="info" %}
For all creatures, Bipedal or Quadrupeds is recommended to add *Colliders* on the main bones of the creatures, Like the **Spine** and the **Head**. You can however add just one *Capsule Collider* to the Root GameObject if you like.
{% endhint %}

![](https://lh4.googleusercontent.com/vIC0-z6Wo9gZKm4xkT83ftRD3dlesFSOOFWJyxK5e3tUJYf54RxQnuem45jEEFY_cNHcpBXbxO-z1FznZg0uL_OYUZIHvjMCaRjfKK8IgomjSmWseHYIULxCoghCxezctcV8Acer)

{% hint style="info" %}
**IMPORTANT**

if you add a Main Collider on the Root of the character, the collider must not touch the ground. that will cause sliding issues on slopes.&#x20;
{% endhint %}

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2F3JA4uj4NiiS1W5Q59hy8%2FUnity_L5PUYsUvWM.gif?alt=media&#x26;token=2184f708-1521-4593-b966-dfb699a8e3bf" alt=""><figcaption><p>Make sure the collider is Not touching the bottom to avoid sliding issues</p></figcaption></figure>

### Layer

The animal controller by default is set to the Layer "**Animal**". All the gameobjects in the animal gameobject hierarchy should be set also to the same layer.&#x20;

Attack Triggers, Interaction Triggers, and other Colliders that are not part of the animal it self should be set on the **Ignore Raycast** Layer.&#x20;

### Animator Controller

The **Animator Controller** is the core Animation Logic for the Animal script. It will communicate back and forward with the Animal script to inform which animations are playing and which [**State**](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/states)**,** [**Mode,** ](https://malbersanimations.gitbook.io/animal-controller/main-components/manimal-controller/modes)or **Stance** the animal is at.

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FRDhH2wgD894cZbYfzLtS%2Fimage.png?alt=media\&token=fce346ea-d524-4cc0-9f77-70e17d771e0e)

For the Animal Controller to work properly, the Animation States are tagged with unique **Tags** to find and check if the active playing animations match those commanded by the Animal component.

Tags like **(`Locomotion, Jump, Idle, Fly, Fall, etc`).**&#x20;

That way the controller knows if the Animator is playing the right animation in the active **State**.

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FanUhLZatn8Wzfv1iyHxC%2Fimage.png?alt=media\&token=17d327c7-5fd8-4020-b7ea-8559b1f0a39a)

{% hint style="info" %}

### On the next pages, you will find what all the Public Parameters on every Group do:

{% endhint %}
