Animation controller plays an essential role in the design and implementation of animation in the game development. It serves as a powerful and flexible system for managing complex state-driven animations.
The animator controller (or animation controller) is a state machine to control the transitions and interactions between the animation clips. It not only play animations; it blends them, layers them, and makes transitions from one to another based on the parameters and conditions set.
Animation clips contain information about the movement of game objects, while the animator controller manages how and when these clips are played.
The main components of the animator controller are explained below.
States: States are the conditions or scenarios in which the animated character or object can exist. Each state is associated with an animation clip. When the controller is in a specific state, it will play the corresponding animation clip.
Transitions: Transitions determine how the controller moves from one state to another. It can be set to happen automatically after a certain time or triggered by certain parameters.
Parameters: Parameters are the variables that the animator controller uses to decide when to transition between states. It includes properties like boolean flags (isJumping
or isRunning
) and triggers.
Layers: Layers allow the stacking of animations, which can be useful for complex characters.
For example, a character can have a base layer controlling motion and a higher layer controlling the upper body or facial expressions.
Each layer can have its own state machine, and layers can be masked to control specific parts of the character.
Blend trees: Blend trees allow for the smoother blending of similar animations based on parameters.
For example, a character's walking and running animations can smoothly transition between each other based on the speed parameter.
Here is a step-by-step guide on how to create and set animator controller in Unity.
Select the GameObject
.
Go to Window > Animation > Animation.
It will add animator controller in the project window.
Go to Window > Animation > Animation
Click on create to create an animation
Alternatively,
Click on Assets > Import New Asset.
Navigate to your animation file.
Click Import.
Select the GameObject
.
Go to Window > Animation > Animator.
An animator window will open.
You should be able to see the animations in the flow chart.
If the animations are not added in the flow chart, drag and drop the animations from the project window into the animator window.
Right click on the grid area in the animator.
Create a state.
Select the state.
Go to the inspector window.
You will be able to see the Motion field.
Click on the circle selector to the right of the Motion field to choose an animation clip.
Transitions allow you to switch smoothly between animations based on the parameters set.
Right click on a state (the animation) .
Choose Make transition.
It will create an arrow you can drag to another state.
Click on the transition arrow to configure it in the inspector.
You can set the conditions under which the transition will occur.
Repeat these steps for each transition you want to make.
Parameters are used to make the transitions on the events happening in the game (user inputs or character speeds).
Open the animator window.
You will be able to see a tab called Parameters.
Click the "+" icon to add a new parameter.
You can choose between a float
, int
, Bool
, and Trigger
.
Note: Remember to set or change the parameters in the
C#
scripts for the transitions to work.
GameObject
Select the GameObject
you want to animate.
In the inspector window, you should be able to see the Animator component.
If not, click on Add Component > Animator.
In the Animator component, click on the circle selector to the right of Controller.
Select the animator controller you created.
Save all the changes.
Click on Play to play the animation.
Your GameObject
should animate according to the states and transitions you set up in your Animator Controller.
The project displays a cube which scales on pressing P
and descales on pressing S
.
import React from 'react'; require('./style.css'); import ReactDOM from 'react-dom'; import App from './app.js'; ReactDOM.render( <App />, document.getElementById('root') );
Free Resources