Unity3d's Mecanim Animation system learning Note (eight): Animator Layers (animation layering)

Source: Internet
Author: User

Solve what problem?

What kinds of problems can be used to solve the animation layering? Imagine if you want to develop a third person shooting game, then it is certainly hope that the body animation into the upper and lower parts, the above according to the location of the target and whether or not to play the animation, under the motion animation. The best example is unity4.x's own example Angrybots.

Avatar Mask

Below we use Avatar mask to achieve the effect of the character waving in the run.

Let's add a character to the scene, add a animator controller to it, and set the jump condition as follows:

Next we add the following script to control the playback of the animation, in order to keep the character from playing animation, remember to cancel the "Apply Root Motion", so that we can see the effect of animation playback.

Add the following script:

1 usingUnityengine;2 usingSystem.Collections;3 4  Public classMasktest:monobehaviour5 {6     PrivateAnimator _animator;7 8     voidStart ()9     {Ten_animator = This. Getcomponent<animator>(); One     } A      -     voidUpdate () -     { the         if(Input.getkeydown (KEYCODE.R)) -         { -_animator. Setbool ("Run",true); -         } +         if(Input.getkeyup (KEYCODE.R)) -         { +_animator. Setbool ("Run",false); A         } at  -Animatorstateinfo state = _animator. Getcurrentanimatorstateinfo (0); -         if(State.shortnamehash = = Animator.stringtohash ("Run") &&Input.getkeydown (KEYCODE.J)) -         { -_animator. Settrigger (" Jump"); -         } in     } -}

Next we want to press the space when the character plays the waving animation, but the running jump animation cannot stop playing.

We need to add a new layer to manage the playback of the waving animations:

At the same time we want to configure the Wave animation, where the idle can not add any animation, simply means that the empty can be, but also added a trigger "wave" to show the condition of the wave into the waving animation.

Next we set up the layer and set its weight to 1:

OK, let's change the code to try it out:

1 usingUnityengine;2 usingSystem.Collections;3 4  Public classMasktest:monobehaviour5 {6     PrivateAnimator _animator;7 8     voidStart ()9     {Ten_animator = This. Getcomponent<animator>(); One     } A      -     voidUpdate () -     { the         if(Input.getkeydown (KEYCODE.R)) -         { -_animator. Setbool ("Run",true); -         } +         if(Input.getkeyup (KEYCODE.R)) -         { +_animator. Setbool ("Run",false); A         } at  -Animatorstateinfo state = _animator. Getcurrentanimatorstateinfo (0); -         if(State.shortnamehash = = Animator.stringtohash ("Run") &&Input.getkeydown (KEYCODE.J)) -         { -_animator. Settrigger (" Jump"); -         } in  -         if(Input.getkeydown (keycode.space)) to         { +_animator. Settrigger ("Wave"); -         } the     } *}

Run it and find out when the other animations stop when you play the waving animation.

The answer is that we need to create a avatar mask to represent the part where we only want to play the animation, that is, the hand animation, the other parts do not play, right-click on the Project window to create a avatar mask file:

Turn off the difference outside the right-hand part:

Here is a transform this option, which controls whether each bone participates in animation, and if our character has wings and tails, something like that will be used.

The final step is to drag this avatar mask into the wave layer of the animator controller:

Run the next game again, we need the effect is not already out of it.

Set up commentary

Let's take a look at the settings of the layer panel:

Weight

The weight of the animation layer, the default base layer must be 1. If set to 0, the animation of the current layer will not play, 1 will play, and 0-1 will play a similar blend of the animation, such as the previous wave of the example, if set to 0.5 the waving animation when the hand will only lift around the neck.

Mask

Animation matte, above has been explained above not to repeat.

Blending

Animation Blending mode:

    • Override: Overwrite, indicates that the animation of the current layer will overwrite the animation of other layers, such as waving to play the right hand can not play other animations;
    • Additive: Adds an animation that represents the amount of animation of the current layer added to other layers, such as waving when the hand is running or standing;
Sync

When this feature is turned on, there are a few more options, as follows:

We can consider this function as a replication feature.

Source layer: Specifies which layer of the current layer is a copy, after which the state of the current layer is fully or fully synchronized with the specified layer, but we can modify the animation of one state.

The effect that this feature provides is that the two state-consistent layers can make a few different adjustments.

Timing: When the current and souurce layers of the same state use an inconsistent animation time, the copied layer is not checked to play at the time of the source layer (the effect is that the copy layer animation may become faster or slower, the source layer animation plays at the same speed), Tick the source layer to play at the time of the copy layer (the effect is that the source layer animation may become faster or slower, and the copy layer animation will play at the same speed).

IK Pass

Indicates that an IK animation is started, and the previous article is not detailed.

Unity3d's Mecanim Animation system learning Note (eight): Animator Layers (animation layering)

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.