Unity3d's Mecanim Animation system learning Note (V): Animator Controller

Source: Internet
Author: User

Brief introduction

Animator Controller in Unity is a file type that exists as a separate configuration file, and the suffix Controller,animator controller includes the following features:

    • Multiple animations can be integrated;
    • The use of state machine to achieve animation playback and switching;
    • can achieve animation fusion and layered playback;
    • The animation can be controlled in depth by the script;

Let's look at the composition of the animation visually through a graph:

The animator component is used to control the playback of character animations, where the two most essential content is the animator controller that controls the animation playback logic and the animated skeleton avatar object.

Animator Components

The role we need to play the animation needs to add the animator component, which is our interface for controlling the animation, let's look at the animator component:

    • Controller: The animator controller file used.
    • Avatar: The skeleton file used.
    • Apply Root Motion: Whether the position of the gameobject that binds the component can be changed by the animation (if there is an animation that changes the displacement).
    • Update mode: Normal means update with update, Animate physics means update with fixupdate (typically used in case of interaction with object), Unscale Time represents an update that ignores timescale (typically used in UI animations).
    • Culling mode: Always animate means that even if the camera does not see the update to be animated, cull update transform indicates that the camera stops playing when it is invisible but the location continues to update, cull Completely all updates that stop the animation when the camera is invisible.

Some of the main information about our animations is also shown below.

Animator Override Controller

We also find a resource when we right-create a resource that means that the animation of each state is modified based on a animator controller, the other settings are the same, and we can easily reuse the animator Controller that we have created.

Create a animator Controller

We can create animator controller in the right-click menu in Project View, and let's look at the newly created animator controller:

First, we found the 3 default states that unity automatically created for us and could not be deleted:

    • Entry: Indicates that when entering the current state, the state of the connected state becomes the first state after entering the state machine;
    • Any state: Represents an arbitrary status, and its function is that the state it points to can be toggled in the past at any time;
    • Exit: Indicates exiting the current state machine, if any state points to the exit, indicating that the current state machine can be exited from the specified state;
Create a new state

1. We can create it from the right-click menu:

2. Or we can create by dragging a animation clip to the State machine window;

We found that the first state we created was set to the default first state, and the first state was marked yellow, as follows:

We can set this state through the inspector window, which is explained in detail in the previous note.

We can use these two methods to create multiple states, and configure each state as follows:

State switching

Our state machine already has a state, but we haven't specified a relationship between each state, let's look at how to specify the relationship between states.

In Mecanim, the play between animations is no longer switched by invoking a method such as "play", but by judging the transformation of the parameters to change the state as the animation.

We open the parameters panel, which is used to set the various parameters used by the state machine, as follows:

Click the plus sign to create a parameter that allows us to create 4 types of parameters in unity:

The parameters of the Float:float type are used to control the floating-point parameters inside the state machine.

The parameters of the Int:int type are used to control the integer parameters inside the state machine.

Bool:bool type parameter, more for state switching;

Trigger: is essentially a bool type parameter, but its value defaults to false, and when set to True, the system automatically reverts it to false;

Below we create two simple variables of type bool, as follows:

We hope that when walk is true, the character moves around, the character stands when it is false, and the run is the same, but it transitions to the running.

Below we can pull a state-transition line by right-clicking the menu to indicate that the current state is transitioning to the target State.

We can click on the line to set the conversion conditions in the inspector window as follows:

We set walk to true in the condition box, which means that when walk is set to true, it jumps from standing to walking animation, likewise, walking back to standing also requires a converted line, but walk to be set to false:

The settings for run are also consistent.

controlling animation transitions

By adding the following new script component on top of the gameobject that binds the animator component, we can switch the animation of the character playing by pressing the key:

1 usingUnityengine;2 usingSystem.Collections;3 4  Public classTestanimchange:monobehaviour5 {6     PrivateAnimator _animator;7 8     voidStart ()9     {Ten_animator = This. Getcomponent<animator>(); One     } A      -     voidUpdate () -     { the         if(Input.getkeydown (KEYCODE.W)) -         { -_animator. Setbool ("Walk",true); -         } +         if(Input.getkeyup (KEYCODE.W)) -         { +_animator. Setbool ("Walk",false); A         } at         if(Input.getkeydown (KEYCODE.R)) -         { -_animator. Setbool ("Run",true); -         } -         if(Input.getkeyup (KEYCODE.R)) -         { in_animator. Setbool ("Run",false); -         } to     } +}

Unity3d's Mecanim Animation system learning Note (V): Animator Controller

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.