First of all we have to import the character. Unity natively imports Maya (.mb or .ma) files, Cinema 4D (.c4d) files, and fbx files which can be exported from most animation packages. Click here to learn how to export from your modelling/animation package.
首先我们输入动画。Unity支持输入Maya (.mb or .ma)文件, Cinema 4D (.c4d)文件,和fbx文件,这些能输出为很多动画包.点击这里学习怎样输出模型/动画包export from your modelling/animation package.
Importing Animations using Animation Splitting
输出动画使用动画片段
The most convenient way for animators to work is to have a single model containing all animations. When importing the animated model, you can define which frames make up each part of the animation. Unity will automatically split the animation into the individual parts, called Animation Clips.
To import the animations you simply place the model in the Assets folder of your project. Unity will now automatically import it. Highlight it in the Project View and edit the Import Settings in the Inspector.
In the Import Settings, the Split Animations table is where you tell Unity which frames in your asset file make up which Animation Clip. The names you specify here are used to activate them in your game.
在输入设置, Split Animations表是告诉Unity你的资源文件的哪些帧是表示哪些动画片段的.你指定在这里的名字在你的游戏使用触发他们.
name Defines the Animation Clip's name within Unity.
first frame The first frame of the animation. The frame number refers to the same frame as in the 3D program used to create the animation.
last frame The last frame of the animation.
loop frame If enabled, an extra loop frame is inserted at the end of the animation. This frame matches the first frame in the clip. Use this if you want to make a looping animation and the first & last frames don't match up exactly.
名字 定义Unity里动画片段的名字.
The other way to import animations is to follow the @ animation naming scheme. You create separate model files and use this naming convention: 'model name'@'animation name'.fbx
另一个输入动画的方法是在动画名后面加@.你创建单独的模型文件和使用这种命名方法'模型名字'@'动画名字'.fbx
An example of four animation files for an animated character
有4个动画文件的动画角色例子
Unity automatically imports all four files and collects all animations to the file without the @ sign in. In the example above, the goober.mb file will be set up to reference idle, jump, walk and wallJump automatically.
When importing animated characters from Maya that are created using IK, you have to check the Bake IK & simulation box in the Import Settings. Otherwise, your character will not animate correctly.
当输入动画角色使用Maya会创建使用IK,你可以检查Bake IK & simulation盒在输入设定.否则你的角色将不能正常运动.
Bringing the character into the Scene
放置角色到场景
When you have imported your model you drag the object from the Project view into the Scene View or Hierarchy.
当你输入模型后,拖拽物体从工程视图到场景视图或层次视图.
The animated character is added by dragging it into the scene
动画角色通过拖拽添加到场景
The character above has three animations in the animation list and no default animation. You can add more animations to the character by dragging animation clips from the Project View on to the character (in either the Hierarchy or Scene View). This will also set the default animation. When you hit Play, the default animation will be played.
TIP: You can use this to quickly test if your animation plays back correctly. Also use the Wrap Mode to view different behaviors of the animation, especially looping.
The actual animating of characters is done through Unity's scripting interface.
真实的角色动画使用Unity脚本接口执行.
Animation Blending
动画合成
In today's games, animation blending is an essential feature to ensure that characters have smooth animations. Animators create separate animations, e.g. a walk cycle,***n cycle, idle animation or shoot animation. At any point in time in your game you need to be able to transition from the idle animation into the walk cycle and vice versa. Of course you don't want any sudden jumps in the motion, you want the animation to smoothly transition.
This is where animation blending comes in. In Unity you can have an arbitrary amount of animations playing on the same character. All animations are blended or added together to generate the final animation.
Our first step will be to make a character smoothly blend between the idle and walk animations. In order to make our job simpler when scripting, we will first set the Wrap Mode of the animation to Loop. Then we will turn off Play Automatically to make sure our script is the only one playing animations.
Our first script for animating the character is quite simple; we only need some way to detect how fast our character is moving, and then fade between walk and idle animation. For this simple test we use the pre-setup input axes.
When you hit the Play button, the character will start walking in place when you hold the up arrow key and return to the idle pose when you release it.