in a previous article, we initially learned about some of Mecanim's very basic classes, and I ended up with a question in the form. This time I came to the answer to this question, in fact, very simple, the last warning is as follows:
4.0 New animation system Mecanim usage (b) ">
The caveat is that the animation clips used in the animator controller needs to have this step of muscle (muscle) set in the Inspector. my English sucks, but I can tell the meaning of this sentence, that is, the animation clip that we use must be animation in the model that has produced the Avatar . Clip. Since we are currently only generating avatar for the first robot, we now have to rigging each robot one at a time, that is, to have robot in each of the Avatar FBX files. It's hard to accept, but it's easy if our robot animations are imported in a way that's a single file split. I thought about it later, and now we're going to introduce the core features of Mecanim--animation redirection should be appropriate enough. All right! Here we go! First we enter the next thing in Assetstore: Mecanim Animation Starter Pack (note that there are many free resources in the Assetstore class for us to download, but we have to register an account first). 4.0 New animation system Mecanim usage (b) ">
4.0 New animation system Mecanim usage (b) ">
This package is a great package, and our next example will be fully used. Note: The source files for the packages downloaded from Assetstore are not in the Unity installation directory, the general address is: C:usersadministratorappdataroamingunityasset Store. To give us a better understanding of the power of the Mecanim animation system, we also have to download a model soldier, of course, in Assetstore:
4.0 New animation system Mecanim usage (ii) ">4.0 new animation system Mecanim usage (ii)" >
Note that there is no animation file in this solider, but Mecanim can animate the solider by animating the redirect. Below we create a new project, named: MECANIM2. Then the two packages we downloaded were brought in. According to the previous article, our husband became a solider avatar (the above two packages contain two FBX files, one is solider and the other is SWAT). Then create a new Animationcontroller, named Solider1. We then look at the FBX files that we imported with Avatar animations, as follows:
4.0 New animation system Mecanim usage (b) "> We're still creating a new two animated state: Idle***n. This time, we tried to find two of the animated segments with avatar in the animation section about Idle***n, respectively, dragged to two animated state corresponding to the motion, we found that we can drag to a position. That was the conclusion I made at the beginning. We then create an animated transition between the two animated states (Animation transitions). such as: 4.0 New animation system Mecanim usage (b) ">
Then we click the arrow from the Idle***n state. On the Inspector panel we saw this:
4.0 New animation system Mecanim usage (b) ">
the part that I marked with the red line is the key to our next state transition. Then we must use the animation parameters. Create a new float named speed animation Parameters (I have an introduction to the previous article). Then we click on the drop-down bar where the red line is labeled, select speed, and we see a little change in this section:
4.0 New animation system Mecanim usage (b) ">
The second drop-down tab has two selections, respectively: greater and less. I filled out 0.1 in the third option to do this: if the speed is greater than 0.1, perform this conversion, that is, the animation state is switched from idle to ***n. This is important, mainly in our script writing. to this our simple animation controller from Idle***n is done. We dragged the solider into the scene view and then dragged the animation controller we just made to the animator in the solider corresponding Inspector panel, just like this: 4.0 New animation system Mecanim usage (b) ">
Note: The apply Root motion option in this animator component, if we tick, changes the character's transform by the amplitude of the animated motion when playing the animation, if we do not tick, We can use the script to set the tranform of this role. that might be a little hard to understand. Don't worry, we'll prove it here. we still build a plane to hold the solider, and add a role controller for solider and adjust the size and position of the capsules appropriately. after the completion we run a try, because at this time we do not have the script to dynamically control the Solider animation state of the switch, so solider will play the default animation: Idle. As follows:
4.0 New animation system Mecanim usage (b) "> we saw that it was solider standing for a while, and turned One direction and placed a poss. We finally got a character that didn't take any animation clips to move up. This is the powerful animated redirection feature of Mecanim, who can attach animations from one character to another, which has never been seen in previous versions of unity. With this function, art can greatly reduce the workload. But we're not finished yet! We have to use the script to achieve the transition of the animated body. So, we have to create a new script, named: Firstmecanimscript. I simply write a few lines of code as follows: using Unityengine; using System.Collections; Public class Firstmecnimscript:monobehaviour { private Animator Animator; private float V; // Use this for initialization void Start () { animator = Gameobject.getcomponent (); } //Update is called once per frame void Update () { v = input.getaxis ("Vertical");
if (animator) { animator. SetFloat ("Speed", v); }
} } The code is surprisingly simple, that is, if we press the vertical arrow key, when the offset is greater than 0.1 (the point at which we define speed is 0.1), the dynamic state immediately transitions from idle to ***n state:
4.0 New animation system Mecanim usage (b) "> The function is actually achieved, but it is important to note that I have previously emphasized that if we tick apply Root motion in animator, we do not have to modify the character's transform, and the transform of the character can be changed by the design of the action itself. But if we do not tick it, then we can only rely on the program to dynamically change its transform, just like the old-fashioned animation system. Well, the reader can examine the problem in person. This time we also realized that Mecanim's animation redirection function is powerful, but we have not finished it! Next we have IK, animation mixed tree and other classes that we need to explore. So, my next post, please look forward to!
Unity3d 4.0 New animation system Mecanim usage (ii)