"Turn" Mecanim animator use detailed

Source: Internet
Author: User

http://blog.csdn.net/myarrow/article/details/45242403

1. Introduction

Mecanim The role design of the game to a new level, using the Mecanim can be retargeting (redirection) to improve the reuse of character animation. When dealing with human character animations, users can use the animation state machine to handle transitions between animations and the logic between animations.

Mecanim supports motion redirection (retargeting) functionality: the ability to apply animations from one role model to another.

2. Animator key element 2.1 animator Component

Gameobject with animator Animation must have a animator component, as shown in the animation component:

The animator component is responsible for assigning animations to Gameobject. The animator consists of the following two key elements:
1) Animator Controller
2) Avatar (define Avatar only if Gameobject is a humanoid character)

Schematic: How a Animator component of a game object combines animation Clips, Animator Controller, and Avatar resources.

2.2 Avatar

One of the basic steps in creating an animation is to create a mapping from the Mecanim system's simplified humanoid skeleton structure to the skeleton structure that the user actually provides , which is called Avatar.

2.2.1 Creating avatar

creating avatar is a critical step in using Mecanim. Avatar's creation process is the analysis of the skeleton structure of the imported role resource, and its internal process is compared to the existing, simplified, standard human skeleton in Mecanim, which is then transformed or identified as a skeleton structure that mecanim can recognize.

Through the creation of Avatar, the retargeting between roles can be realized.

1) After importing a role model file (such as FBX), select the imported role in the Project window, and then specify the model's rig as humanoid in its inspector window, then click the Apply button


2) after clicking "Apply", Mecanim tries to match the character's existing bone structure to Avatar's skeleton structure (in most cases, Mecanim can do it automatically), and if the match succeeds, there is a "V" symbol next to "Configure", as shown in:

3) After a successful match, the Avatar sub-asset is added below the model asset, as shown in the Project window:

4) Select Avatar Sub-asset (for example, Ethanavatar in), Inspector window as shown, Avatar and mapping can be configured after the point "Configure muscles".


2.2.2 Configuration Avatar

Avatar is an extremely important module in the Mecanim system, so it is important to set the avatar correctly for the model resources. Regardless of whether Avatar's automatic creation is successful, users need to go into the Configure Avatar interface to confirm the validity of Avatar, confirming that the user-supplied skeleton structure is correctly matched to the Mecanim-predefined skeleton structure and that the model is already in the T-shape stance.

1) Solid Circle: the bones must match

2) Dashed circle: The bone is an optional match
Optional match bone games are automatically interpolated based on the state of the bone that must be matched. To facilitate mecanim bone matching, the user-supplied skeleton should contain all the bones that must be matched. In order to improve the odds of matching, we should try to name the bones by the parts represented by the bones (e.g., the left hand is named Leftarm).

3) avatar is automatically created successfully with the following interface:

4) Avatar automatic creation failed with the following interface:

5) Avatar Configure Inspector (bone mapping)

6) if auto-mapping (mapping->automap) partially or completely fails, you can drag the bones in the scene to assign them. If Mecanim believes the bone is reasonable, it is shown in green in Avatar Inspector, otherwise it is displayed in red.


7) If the bones are bound correctly, but the character poses incorrectly (not the standard T-shape), the message "Character not in T-pose" can be seen in the scene to resolve this problem by Pose->enforce t-pose or rotating other bones.

2.2.3 Muscle Setting

1) Mecanim allows the use of "muscle" to control the range of motion of different bones.
2) When Avatar is created and successfully configured, Mecanim understands the skeleton structure and allows the relevant parameters to be adjusted in the Muscles tab of Avatar Inspector. Here you can adjust the motion range of the character to make sure that the bones move up to true and natural.

For detailed usage See: http://www.unitymanual.com/thread-1211-1-1.html

3) control the motion range of the non-active bone by setting the rotation range of each joint.

2.3 Animator Controller

Responsible for defining which animation footage to use, and when and how to play (Dissolve <blend> and transition <transition>) these animated footage.

The Animator Controller maintains a series of animations in the form of state machines, and toggles the animation when a specific event occurs for a subordinate role.

2.3.1 Creating a animator Controller

In the Project window, create a animator controller, and then double-click the animator controller you just created to edit it in the animator window. Create the animator controller as shown in:

2.3.2 Edit Animator Controller2.3.2.1 Create state node

Drag animation clip from the Project window to the animator window, the corresponding state node is created automatically, and the first dragged animation clip is the default state node, as shown in:

2.3.2.2 Setting State transitions

State transformations: Transitions from one state to another, such as from a idleshort state to a jump state.

2.3.2.2.1 Character Auto Motion

simple and without programming state transformations, programs cannot control

A line with arrows that transitions from one state to another indicates that these arrows are used to set the transformation condition, such as: under what conditions to transition from the Idleshort state to the jump state.

When you set a state transform, the arrow lines are selected, and the transformation conditions are set in inspector, such as setting the transform condition based on the percentage played.

When the Idleshort status plays to 90%, it switches to the run state.

When you are finished setting up, close the animator window. At this point, a simple animator controller with no programming is already set up.

2.3.2.2.2 Program Control role Movement

1. Create a hybrid tree

1) If a state node supports multiple motions (for example: Run supports Rundirect, Runleft, runright), selects this node right-click, and then points "Create new Blendtree in", then the motion of this state node is: Blend Tree

2) After you create the Blendtree, double-click the state node to enter the edit of the mixed tree.  

3) Select the blend tree, in its Inspector panel, click the button "+" and then click "Add Motion Field" to add 3 motion, and then set the corresponding motion, with the following result:

2. Create the control parameters and set the transformation criteria

1) Create control parameters

2) Set the arrow line transform condition

Select the arrow line first, and then set the transform condition for this arrow.

3) Set the mixed-tree transformation criteria

Direction:

-1: Play animation Runleft

0: Drag and drop animation run

1: Play Animation runright

Blend type:1d (represents a parameter that controls the animation playback of a mixed tree)

2.3.2.3 Animation synthesis

For example, if a character runs while swinging a sword, it needs to synthesize two animations. To achieve a composition of two animations, you need to create an animation layer separately.

Weight: The weight value of the animation layer

Mask: The action of this layer affects which part of the body (mask)

1) Create Avatar Mask: Create a avatar mask in the Project window

2) Click on the unaffected parts to make it red, such as only the right-handed exercise to participate in the calculation, that is, only the right hand action will occur, so as to achieve the purpose of shielding the rest of the body, thereby improving the efficiency (IK: To show the wind direction dynamics)

3) Apply Avatar Mask to a specific animation layer

4) Set the state transition condition in the script and then bind the script to the character.

Summary: A animator controller can contain multiple animation layers, each animation layer according to its set of state machine run alone, and then according to its weight the animation layer is synthesized, the subsequent animation layer (except the base layer) only display its avatar Mask the green part.

2.3.3 Application Animator Controller

1) Select the role in the Hieratchy window that requires animator animation

2) Drag the animator controller resource in project to the Controller input box of the animator component of the Role object, or select it by the button next to the point

3. Animator Redirection function

REDIRECT function: Applies the action applied to one character to another.

That is, the same animator controller can be used for different animators.

4. Animator Detailed parameters

Animator detailed parameters See: http://docs.unity3d.com/ScriptReference/Animator.html

Http://edu.china.unity3d.com/learning_document/getData?file=/Manual/MecanimAnimationSystem.html

5. Set the animation state transition code

Set the animation state Transition code example (IdleRunJump.cs) as follows:

[CSharp]View PlainCopy 
  1. Using Unityengine;
  2. Using System.Collections;
  3. Public class Idlerunjump:monobehaviour {
  4. protected Animator Animator;
  5. public Float directiondamptime =. 25f;
  6. public bool applygravity = true;
  7. // Use this for initialization
  8. void Start ()
  9. {
  10. Animator = Getcomponent<animator> ();
  11. if (animator.layercount >= 2)
  12. Animator. Setlayerweight (1, 1);
  13. }
  14. //Update is called once per frame
  15. void Update ()
  16. {
  17. if (animator)
  18. {
  19. Animatorstateinfo StateInfo = animator. Getcurrentanimatorstateinfo (0);
  20. if (Stateinfo.isname ("Base layer.run"))
  21. {
  22. if (Input.getbutton ("Fire1")) animator.                  Setbool ("Jump", true);
  23. }
  24. Else
  25. {
  26. Animator.                  Setbool ("Jump", false);
  27. }
  28. if (Input.getbuttondown ("Fire2") &&animator.layercount >= 2)
  29. {
  30. Animator. Setbool ("Hi",!animator.  Getbool ("Hi"));
  31. }
  32. float h = input.getaxis ("horizontal");
  33. Float v = input.getaxis ("Vertical");
  34. Animator.  SetFloat ("Speed", h*h+v*v);
  35. Animator.     SetFloat ("Direction", H, Directiondamptime, time.deltatime);
  36. }
  37. }
  38. }

6. Create a role for the Mecanim system

The following three phases are mainly involved in creating a role for the Mecanim system:

1) Modeling

The role model has reasonable topological structure, model export setting, model import Unity3d; make the character t-pose; remove unwanted faces, vertices and hidden faces and vertices;

2) Bone setting

3) Skin

The process of binding a polygon's mesh vertex to a bone.

7. The difference between muscle setting and body mask

1) Muscle settings: is set to Avatar, so it modifies the input settings of the avatar and is valid for all animations.

2) Body Mask: Is the animation is set (each animation clip has a body Mask), only modify the properties of this animation, that is, only valid for this animation.

"Go" Mecanim animator Use the detailed

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.