U3D mecanim Animation

Source: Internet
Author: User

As the main update function of unity4.0, mecanim animation has been placed on a lot of expectations. There are advanced and inadequate systems. We will summarize these points at the end.

A Zhao gave a rough look and wrote down the following tutorials. This tutorial briefly describes the usage and Control Methods of the mecanim system. The resources used in this tutorial are downloaded from assetstore. If you are interested, you can download them for free.

Objective:

I have prepared several 3D models with no animation in advance, in fbx format, and then some exported animation files.

What we need to do is to use a new animation system to make these animations into a state machine and assign them to these non-animated models. The advantage of this is that we can separate the model creation and animation production. As long as our models skin separately, we can share the same animation at will. If the state machine is properly controlled, it is easier to control the animation of characters.

 

Preparations:

Prepare several fbx models that are well understood but have no action:

Several ready-made animation files. These files can be exported directly using Maya or using 3dmax to directly export fbx files with animations, and then cut them in the Unity import tool.

 

The cutting process is the same as that of the previous animation system:

 

 

Start production:

From unity4.0, the options of the model Importer have changed a lot. The options include model, rig, and animations.

The "model" tab is similar to the previous basic settings. You can also set the grid, normal, index, and material:

The content in the animations label bar is the same as that in the preceding cutting animation. However, for models without an animation, we can cancel the option of importing an animation.

The rig label bar focuses on:

To use the new mecanim system, we must make the model have a set avatar. Therefore, we must select the contents in the rig as follows:

Avatar can be created from its own model or copied from another avatar. After selection, you can open the Avatar editor by clicking the red box in the image.

 

Find the fbx model in the project resource browser. We can see that the file marked in the red box is the avatar of the model.

You can also open the Avatar editor here.

 

 

Next we will start to make Avatar:

When you open Avatar, you will be prompted to save the existing scenario. Because avatar will open a new independent scenario for editing.

This is the Avatar option. Divided into four parts: body, Head, left hand and right hand. Each part has several bones. What we need to do is to specify the bones of the characters we have prepared to these parts.

I don't need to explain it too much here. When you click an option, the above body map will mark the selected part, which is more intuitive.

 

If it is difficult to specify the bones one by one, we can also select automap from the mapping below, so that unity will help you identify the character structure and specify the skeleton. I tried it and the automatic adaptation accuracy is still very high. However, you must specify some details, such as fingers and eyes. In addition to automatic adaptation, we can also save and read settings.

 

If this parameter is specified, we want to save it. However, the system prompts that the role is not in the T position.

 

Select enforce T-pose in pose.

 

In this way, the role will become a T-shaped posture. Now we can save this avatar.

You can also test the effect of the skin in the muscles bar. You can perform some actions on different parts, such as bending the body and twisting the waist, to check whether the skin effect is normal.

 

Next we will create an animation controller.

The required materials are the animations we have just prepared.

 

 

This is the animation or component of the mecanim animation system. You only need to drag the fbx model to the scene to see it:

Drag it to the scene and find that the model does not play the animation, because the animation controller is missing in the red box. Next we will make our own animation controller.

 

Right-click the project resource manager to create an animation or controller.

 

A new animator controller is created.

 

Next we need to open the animator editing panel:

 

This is the default animator panel:

 

 

Select the newly created animator controller and drag the animation into the animation panel:

 

Now we have four animations in our controller. If you drag the Controller to the character, the character will play the default action. The default action is death. We want to specify the default action as idle2.

Right-click idle2 and select set as default:

 

At this time, the color of idle2 has changed, and it becomes the default action:

 

 

Next, let's analyze what the square with "idle2" indicates:

In the attribute column, we can see that this square represents an action. You can set the playback speed for this square. You can specify the animated fragment represented in the square. You can specify whether to enable foot IK. Even if the square we dragged is idle2, We can manually select another animation clip here.

 

In addition to representing the existing animation fragments, this square also represents the fusion of several animations.

Here we need to create a new hybrid tree:

Right-click idle2 and choose create newblendtree in state.

 

Now let's look at the attributes. We can see that in motion, there is no longer an existing animation fragment, but a blend tree.

 

 

Double-click idle2 to enter the next level.

There is a blend tree in it.

 

Click the plus sign in the property bar to add multiple animations to the hybrid tree.

 

For example, we create two new animated clips and drag idle0 and idle2 into the animation.

 

Looking at the diagram of the hybrid tree, we can see two nodes. We can adjust the blend number to control the influence weight of the animation mix.

 

 

So far, we have understood the content represented by the animated square.

What we need to do next is to connect these animations. For example, from idle2 to death, we can establish a one-way direct conversion. This means that when a certain condition is reached, the role will change from an idle2 animation to a death animation.

Right-click idle2 and select make transition to pull an arrow line segment:

Of course, in turn, you can create an arrow line segment from death to idle2.

 

 

As I said just now, this arrow line segment represents the animation conversion after a certain condition is reached. Where can I set this condition?

We can select an arrow line segment, and then

You can see that this line segment is set in the attribute column. Includes the transition between the previous animation and the next animation, as well as the conditions for the transition ). You can add multiple conditions by the plus sign.

 

Now we click the first default condition (exit time), and we find that there are no other options. That is to say, currently, the animation can only be transitioned using time as the condition, when an animation is played for a certain period of time, it will be switched to the next animation.

 

So how to set other conditions?

In the lower left corner of the animator panel, find the parameter option and click the plus sign to add it.

 

For example, we create two Boolean parameters.

 

After the parameter is created, enter the parameter name. Here we want to use Boolean to control whether the animation can be converted. Therefore, we name the two parameters idle2todeath and deathtoidle2.

 

 

Now back to the selected condition, we found that,

The two parameters set just now can be selected, which means that when I set the line conditions from idle2 to death to idle2todeath, only when idle2todeath is true, the conversion of this animation will be true.

In order to test, we keep the default exit time for the line from idle2 to death, but change the line from death to idle2 to deathtoidle2.

 

Now we can drag the new animator controller to the character:

 

Playing now, we can see that the character first shows the idle2 animation, then play the death animation, and finally the character will not move to the ground. This is because the conditions from idle2 to death are time, so after a certain period of time, the death will be played. However, after the death is reached, the condition for returning to idle2 is deathtoidle2 = true, the default value is false, so the character cannot return to idle2.

 

To enable the characters to return to the idle2 state as we want, we need to write a script:

When you press the button, use the setbool method to set the specified deathtoidle2 to true.

 

Drag the script to the camera or an object, and then drag the character to the animator variable. Then play the video. We can see that a button is added to the screen. When the character falls down, we press this button and the character will return to the idle2 state. However, there is a problem at this time, the character cannot go to the death reverse state. This is because, when we press the button, we change deathtoidle2 to true permanently. In this way, as long as the character reaches the death state, it immediately changes back to the idle2 state.

 

This obviously won't work, so we can make some modifications to the script:

An animatorstateinfo is used to judge the status of the current state machine. What if it is an action of a layer. This is how it works.

Then, based on the actual situation, the variable with the Boolean value true is returned to false under certain conditions.

 

Then fill in an element "idle2" in cmds ".

 

Now play the video again and you will find that the character will not get up after it goes down. Then press the button and the character will get up to idle2 again, and then fall down again.

 

If we add other actions, it will have the following effect:

Except death to idle2, a Boolean condition is required, and time is used as the condition for other unidirectional lines. At this time, we can see that the character first performs the idle2 action, then the idle1 action, then the idle0 action, and finally the death action. When it falls down, it will not get up. After pressing the button, the character will get up, repeat the above action, and finally fall down.

 

Here we are prompted that we can use such one-way lines and conditions to connect some individual actions into a complete set of actions, the most commonly used is the scene animation, or an action game.

When we understand the boolean control, we can also use other parameters as conditions.

For example, you can use float as a condition to connect the standing, walking, and running actions, and then control the status of the three actions through the actual movement speed of the characters.

 

 

Finally, let's complete the above example.

 

Connect the four animations, except that idle0 to idle2 and idle1 to idle2 are controlled by time, while others are controlled by Boolean. So we have to add the corresponding parameters.

 

What does this structure represent? It indicates that the default action is idle2. After playing idle0 and idle1, it will return to the default idle2. We can use buttons to control idle2 to various actions, and also use buttons to control idle2 when death returns to idle2.

 

In the final script, modify the checkstate method:

 

Now, our character can use scripts to control the transition between various action states.

If another role needs to do the same thing, you only need to create Avatar for that role model, then drag the previously prepared animator controller to him, so that the animation between different models can be shared.

 

After completing the example, let's talk about the advantages and disadvantages of the mecanim animation system.

Advantages:

1. models with different bones can easily share bone animations;

2. State Machine Control is systematic.

 

Disadvantages:

1. Unity's built-in Avatar seems to only target the standard two-foot creature, such as human. Of course you can still make an estimate of the four categories, but it may not work. In addition, if the character has wings, floating bands, skirts, and other bones, it cannot directly correspond to Avatar.

2. the animator controller must be manually dragged to the animation or component of the character model. Although there are also ways to specify the editor in batches. However, it is very difficult to use a script to modify the animator controller during the running process after the release (not absolutely not, but a special method is required ). This increases the dependency on the editor and reduces the flexibility of control.

3. mecainm system animation is not applicable to assetbundle. That is to say, this animation system cannot be used for dynamic loading of network resources. The entire role can be exported with the animator controller or separately, and cannot be used after being loaded. This is a fatal injury. You can only do some small demos, or put all the resources together to package and release the project.

 

According to Zhao's feeling, the new animation System of unity3d is still in its infancy, and it is still a long way from normal project use. Unfortunately, unity was eager to launch it in 4.0 and used it as the default animation component. This will cause great inconvenience to those who use unity for project development. We hope unity will continue to improve this function to make it truly powerful.

U3D mecanim Animation

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.