Hello everyone, I'm Qin Yuanpei. Welcome to follow my blog. My blog address is blog.csdn.net/qinyuanpei. The blogger finally wrote this article at the end of this month. This month, because the final exam has not had time to study much about the technical aspects. Although the blog has been updated, I still have a clear understanding of the quality of the article. So, as the last article of this month, what the blogger wants to share with you today is the Mecanim animation System in Unity3D. The blogger wanted to write this article for a long time, but for various reasons, he has never had the opportunity to study this issue in depth, and the test time in the past few days has become quite plentiful, so the blogger took the time to study this problem. The Mecanim animation system is a brand new animation system released by Unity3D. It has many new features such as redirection and fusion. through close cooperation with the staff, it helps programmers quickly design role animations.
The title of today's article is "Unity3D game development when the Fairy sword meets the Mecanim animation system". Why is this question? This is because the blogger wants to share with you the redirection feature of the Mecanim animation system. As we all know, Legend of the legend of the fairy sword is a classic RPG Game, which is still active today. On the Internet, the blogger met a small team who made the legend of the legend, the game is based on Unity3D. Due to technical consistency, the blogger requested some game materials from them, which became a major reason why the blogger was determined to study the Mecanim animation system. It is a model of the legend in "Legend of the legend:
When we got this model, the blogger found that all the animations of this model were placed in an AnimationClip. Therefore, the blogger decisively split the animation file, the division method is to find the AnimationClip in the Resource Directory, and then select the "+" tab in the Properties window on the right to create an AnmationClip, after the number of frames at the starting and ending points is specified, the animation is split. List of animation files after the operator is split:
We can see that the blogger splits an Animation clip into four animated fragments, so that we can play the Animation through the Animation component. This is the animation control format used by Unity3D before the Mecanim animation system was released. This model has problems during modeling, which leads to an error in the role's angle in the game scenario. The blogger had to use the 3D modeling software for adjustment, as a result, it was unexpectedly discovered that there were bones in the model. The blogger suddenly came up with a question: Can I use the Mecanim animation system to add an animation for this model? The answer is yes. Since the animation and the model are created together during modeling, we need to first remove the animation from the model, because one of the main ideas of the Mecanim animation system is to allow an animation to be redirected to different models. Since an animation is available, the built-in animation of the model can be temporarily removed. The method for removing an animation from a model is very simple, that is, when exporting the FBX model, do not select the embedded media option, so that our model can be separated from the animation, after this step, we officially started the explanation of the Mecanim animation system. To understand the Mecanim animation system, you must first understand the following concepts:
1. Avater, I .e., Avatar, is an interface for implementing animation binding in the Mecanim animation system. This interface can be used to match the skeleton and muscle system, so as to ensure that the role is performing the animation, the role can be moved according to the preset animation. First, we found the model file in the project resource window,
We noticed that there are three tabs in the Properties window on the right: Model, Rig, and Animations. Here, we select the Rig tab and set the Animation Type to Humanoid, that is, an Animation of the double foot Type. This type supports most humanoid models. In addition, the Lagacy type is used to be compatible with model animations in earlier versions of Unity3D. The Generic type is a common type between humanoid and non-humanoid models. After selecting the Humanoid type, generate the Avater type. Then, Create Form This Model is generated using the current Model to generate an Avater. In this case, the Configure button is changed from unavailable to available. Click this button. If we do not save the game scenario, Unity3D will prompt you to save the scenario. We choose to save it directly, next, let's start a new scenario,
In this scenario, the skeleton structure of the model is displayed. Correspondingly, the main body structure of the model is displayed in the right window. You can see that all the points in the right window are displayed in green, this indicates that the current model's skeleton joints and models match correctly. In this case, we can switch to the Muscles tab. This is to check whether the model matching is correct by dragging the slider. When using Avater, pay attention to the following two points:
1. If there are no serious errors in Model Modeling, you can use the Mipping-> AutoMap at the bottom of the window to achieve automatic model matching, which can improve work efficiency, however, as a program developer, we must not rely heavily on this function.
2. If a T-Pose error is prompted when you manually adjust the model matching, you can use Pose-> Enforce T-Pose to implement forced conversion. The blogger has recently started learning game modeling, so we may not be able to explain it clearly for the time being. Let's talk about it as an experience.
Click Done to edit the model.
Ii. AnimatorController: If Avater is an interface that matches the body and skeleton of a model, AnimatorController is an interface for binding an animation and a model. Here we create a XiaAnimaterController. Double-click the file to open the Animator window,
The blogger does not want to introduce in detail the concepts of state machines and hybrid trees in Unity3D animation systems, because these concepts are difficult to explain now, the blogger intends to explain in detail the concept of the state machine and hybrid tree of Mecanim animation in the next article. Today, we only have a preliminary understanding of the Mecanim animation system, because it is not an overnight task to fully understand the animation system. The blogger creates six animation states and connects them with arrows. What functions does the blogger want to implement? The blogger hopes to trigger corresponding conditions under certain conditions and return to the default status immediately after departure. The default status here is Idle. It is estimated that everyone will be a little confused here. I didn't say there was no animation in this model before the blogger, so where did the animation come from? In this regard, the blogger will give an explanation here. Before creating this project, the blogger prepared an animation package named WomanKnightAnimationPack in advance, which provides commonly used animations in the game, here we will use the Mecanim redirection function to apply this animation to our model. This animation package can be downloaded from the official resource store. Now, let's explain how to bind an animation to a model. Click the default Idle animation and the following content will be displayed on the right side of the window:
Through the Motion text box, we can bind an animation to the current state, and select the Foot IK and Mirror options to solve the problems that occur during the walking or running of the role, however, when I checked the API documentation, the blogger did not find the relevant explanation. If any one of them knows, I hope I can tell the blogger. Similarly, we can bind an animation clip to different states, but the problem is coming soon. How can we play the corresponding animation as appropriate based on game planning? This is the animation trigger problem. The blogger asks you to think about the concept of a finite state machine. If you do not know this concept, please understand it on your own, this is a very important and useful concept in game design. We know that in finite state machines, no matter whether we use the switch-case structure or the if-else structure, a state value is required as the basis for judgment. Therefore, this principle still applies to Mecanim. Because the Mecanim animation system is based on the state machine. Now let's create a status value .,
In the Mecanim animation system, four types of State values are provided: Float, Int, Bool, and Trigger. The Trigger and OnTrigger () methods can be used together to enable triggered playback of the animation. Now, we create a status value for an integer. The default value is 0. First, select the Idle-> Walk route. In the window on the right, set the parameter to ActionID, set the value to 1, and set the method to Equals, it means that the Walk animation is executed when the ActionID is set to 1. Similarly, we select the route "Walk-> Idle", set the parameter to ActionID, set the value to 0, and set the method to Equals, it indicates that an Idle animation is executed when the ActionID value is 1. The other animation status parameters are the same as the Walk setting method. The routes starting from Idle are 1, 2, 3, 4, and 5 in sequence, and the routes pointing to Idle are all 0. Now we specify this AnimatorController to the model in the scenario,
Now we run the program. Since we have specified the default animation for the animation, we will see:
Although this animation is a little difficult to match with our ghost girl, we have mastered the method of using the Mecanim animation system. Now, let's write a script to control the character switching animation, because only the default animation has no practical purpose:
Using UnityEngine; using System. collections; public class MecanimController: MonoBehaviour {// Mecanim animation component private Animator mAnim; void Start () {mAnim = GetComponent <Animator> ();} void Update () {// if you press W, Walk forward if (Input. getKey (KeyCode. w) {// play the animation mAnim. setInteger ("ActionID", 1); transform. translate (Vector3.forward * 2.5f * Time. deltaTime);} // if Shift + W is pressed, run forward if (Input. getKey (KeyCode. w) & Input. getKey (KeyCode. leftShift) {// play the running animation mAnim. setInteger ("ActionID", 2); transform. translate (Vector3.forward * 2.5f * Time. deltaTime);} // If you press I, the attack animation 1if (Input. getKey (KeyCode. i) {// play the attack animation 1mAnim. setInteger ("ActionID", 3);} // If J is pressed, the attack animation 2if (Input. getKey (KeyCode. j) {// play the attack animation 2mAnim. setInteger ("ActionID", 4);} // If you press K, the attack animation 3if (Input. getKey (KeyCode. k) {// play the attack animation 3mAnim. setInteger ("ActionID", 5);} // if each key bit is released, it is restored to the Idle status if (Input. getKeyUp (KeyCode. w) | Input. getKeyUp (KeyCode. i) | Input. getKeyUp (KeyCode. j) | Input. getKeyUp (KeyCode. j) | Input. getKeyUp (KeyCode. k) | Input. getKeyUp (KeyCode. leftShift) {// play the standby animation mAnim. setInteger ("ActionID", 0 );}}}
Finally, let's take a look at the actual results!
The terrain in the scenario is created by the terrain tool provided by Unity3D. The real blogger wants to set up the yunlaishi scenario in "Legend of the legend", because the blogger firmly believes that, with the wisdom of xuanxuan, how could he not think of calling yunlaishi after both of them fell into the cliff? Therefore, the blogger believed that neither of them was dead, because mujie's instant look was joyful, there were two footsteps behind the scenes: a rush and a slow wait, so you can imagine the ending. In the "Legend of the legend, maybe this is the reason why the series of games in Legend of the legend, instead, we chose inaction. Previously, the blogger heard of a game "legend 4: back to the starting point" initiated by xianjian players. At that time, he was excited for a while when he saw the promotion and animation of the game, however, the game was terminated due to the disbanding of the production team, which seems to be reminiscent of the past of Shanghai Soft star. Careful friends must have discovered that the model used by the blogger is in xianjian Si. It can be found that this model is relatively simple, and the trees are basically made of paper, the shadow was created in the model. In that year, Gong changjun led shangsoft to create xianjian 3, xianjian 3, and xianjian 4. However, at present, the Shanghai candle dragon, composed of the core backbone of shangsoft, has come out of its predicament and become the third sword to compete with Daewoo's two swords. Why do bloggers always love swords? Because the legend of the sword remains everlasting. Well, thank you for your attention to my blog. Today's content is like this. I hope you will like it.
Learning Mecanim animation system recommendations video address: http://www.tudou.com/programs/view/Ul78LC6rukI/
Daily Rumor: it is not difficult for us to do things, but hard for us to do things.
If you like my blog, please remember my name: Qin Yuanpei. My blog address is blog.csdn.net/qinyuanpei.
Reprinted please indicate the source, Author: Qin Yuanpei, the source of this article: http://blog.csdn.net/qinyuanpei/article/details/35330525