The Unity animation system, also known as “Mecanim”, provides the following features:

  • Simple workflow for setting all elements of animation, including objects, characters and properties.
  • Support to import animation segments created externally and animation segments created using the built-in animation editor.
  • Human animation has been repositioned so that the motion control of the animated character can be shared by all the character models, i.e. the SkinedMesh and Animator are separate, and they are combined to form the final animation.
  • A simplified workflow for editing animation state, the animation controller.
  • Easy to preview animation segments, as well as interpolation between segments. This allows the animator to work independently of the programmer and preview prototypes and preview animations without having to run the game.
  • Manage the complex interactions between animation and visual programming tools.
  • Different body parts can be controlled using different animation logic.
  • Animation layering and masking features.

The keyword

Animation Animation Avatar Avatar Definition Controller Controller


Today is a new day. Move your hand and be happy

New scene

Create a 3D scene and use all 3D resources.

Into the model

Create a new folder to store the model files

Find the root directory of your imported model, which contains files related to the model, texture maps, and so on. There are two ways to import

  1. In the Unity Project view, right-click the folder -> Import New Asset to import
  2. Copy files directly from Windows File Manager to the unity specified directory

After the import is complete, a prompt box will pop up, asking about the material association. The sage fix now lets the editor decide by itself.

Basic setup of model

After import, there will be many. FBX model resources in the Project panel. We select the first one to bind the bones.

Bind the bones in the Inspector

There is a Scale Factor attribute in the Model that can be used to set the Scale of the Model to be added to the scene. Sometimes the Scale of the Model provided by the animator is not appropriate. This attribute can be used to adjust the Model to fit the scene. To animate a skeleton in a Rig, you need to specify several parameters.

Set Animation Type to Humanold to indicate that a humanoid Animation is used. In Avatar Definition and skeleton setting, Create From This Model means to Create a separate skeleton Copy for This Model From Other Avatar and to use the bound skeleton of Other models. Since skeletal models can be reused, we choose the first item here.

After applying the Settings, click Configure to go to the bone Settings screen.

Since the “Avatar” is an important aspect of the Mecanim system, you need to configure an appropriate Avatar for your model. Therefore, no matter the automatic creation of Avatar fails or succeeds, you need to enter the “Avatar Configuration” mode to check to ensure that the “Avatar” is valid and set correctly. Most importantly, your character’s bone structure needs to match Mecanim’s predetermined bone structure, and the model is in a “T” posture. If Mecanim fails to create an Avatar, you will see a “x” mark next to the “Configure” button. If the match is successful, you’ll see a “√” tag next to the “Configure” menu.

When you go to the Configure menu, the editor will ask you to save the scene. The reason for this is that in configuration mode, the scene view is used to show the skeleton, muscle, and animation information for the selected model separately, without showing the rest of the scene. An interface like this is what you can see, which may vary slightly between different versions of the editor.

In the right Mapping interface, click the joint part of the green man to find the specified property, and then bind the corresponding object in the left Hierarchy. Use the common object binding method in Unity to drag and drop the object into the corresponding parameter box.

In general, animators provide more standard model materials to facilitate your 3D production. For bone bindings, Unity provides automatic recognition. In the Mapping drop-down, there are the following options: Clear can Clear all binding joints. Automap can be automatically bound. In the case of automatic binding, there are certain requirements on the standard degree of the model, and some bindings may be inappropriate. Further adjustment.

The Muscles can be used for joint motion in the current model, so it’s easier to see the bone adaptation in this dynamic way.

When you have a good Avatar, click the Done option to go to the next step.

Animator

Create an Animator Controller in the resourceWhat is an Animator Controller?In the game, the animation of characters will change according to the changes of the player’s operation, which means that a model has to switch between different bone animations. The Animator Controller appears to facilitate the implementation of this function. To implement this function, you must add the Animator Controller component to your Gameobject. The Animator Controller component is automatically added to a set model object, such as the imported model, when it is added to the scene.

Double-click the Animator Controller resource file to enter the Editing interface of the Animator

The Layers/Parameters panel

This area is actually made up of two tabs, Layers and Parameters. The contents of the Layers TAB are rarely used in smaller projects and are hard to learn without a specific character model, so you can ignore them for now. The Parameters TAB contains all the “Parameters” we use in the Animator. In a controller with multiple animated shorts, it is through Parameters that the transition between different animations is realized.

Current Layer state machine

This area is the most important part of the Animator, and previously we referred to them as “colored rectangles,” but they are officially called State machines. A State Machine consists of different states and transitions between them. If you want to learn more about a State Machine, check out the Unity manual for the State Machine Basics, which is essentially a special directed graph.

Now drag and drop the animation slices from the resource file into the current Layer state machine. The first animation is set to default state by default. Right-click on the different state machines -> Set as Layer default State.

Right click -> Make Transiton to connect the lines between the different state machines. The arrow of the line represents the direction of the transition between the state machines.

For example, if you want a bool variable to determine whether the role is running, you can add a bool variable here and call it runing.

Now this state and relatively simple, only need to make it to the left and right change. Add a float variable to this and name it Angular. Just to understand what the variables are,

  • Right turn when Angular >0.1
  • Angular <-0.1 turns left
  • 0.1 < presents < 0.1

Select the transition line (the white line with an arrow), add a condition to it, and select the judgment variable and the comparison symbol. Greater means Greater than, and less means less.

In the same transition set of multiple judgment conditions are and, if you add or relationship conditions, then connect a few lines.

Put the Default Avatar into the scene, and the Animator component conyroller attribute specifies that DefaultAnimator is required.

Running the scene is already animating, but there is no animation state change.

Modify state machine variables in scripts

Create a script that can be attached to any object in the scene. Generally speaking, the scripte component that controls the object will also be on its own. Write the following script to control Angular variables Input.GetAxis("Horizontal")You can get a float value in the range (-1, 1) based on when the W /s key was pressed and when it was pressed. Animator.setfloat () assigns the specified value to a variable in the animator.

At this point, a basic interactive skeleton animation is complete, if you need to learn more about how to use the official documentation.