- 最后登录
- 2018-6-29
- 注册时间
- 2011-7-1
- 阅读权限
- 20
- 积分
- 359
- 纳金币
- 335582
- 精华
- 0
|
Character Animation
角色动画
Unity Manual > User Guide > Creating Gameplay > Character Animation
Unity手册 > 使用指南 > 创建游戏 > 角色动画
Unity's Animation System allows you to create beautifully animated skinned characters. The Animation System supports animation blending, mixing, additive animations, walk cycle time synchronization, animation layers, control over all aspects of the animation playback (time, speed, blend-weights), mesh skinning with 1, 2 or 4 bones per vertex and finally physically based ragdolls.
Unity的动画系统允许你创建漂亮的动画角色.动画系统支持动画合成,混合,添加动画,步调周期时间同步,动画层,控制所有方面的动画回放(时间,速度,混合-偏重),网格面每个三角有1,2或4个骨骼,且完成基本的物理玩偶.
There are some best practices for creating a rigged character with optimal performance in Unity. It is recommended that you read about these techniques on the Modeling Optimized Characters page.
这里有一些最好的方法创建一个作弊的角色在Unity获得最好的展示.推荐你阅读下Modeling Optimized Characters页面上的教程。
Making an animated character involves two things; moving them through the world and animating them accordingly.
制作一个动画角色需要2个东西;移动他在世界中和做相应的动作.
This page focuses on the animation. If you want to learn more about moving characters around (for a Super Mario Bros style game or a first-person shooter), take a look at the Character Controller page.
这个页面致力于动画.如果你想要学习更多关于移动角色的(为一个超级玛丽风格游戏或第一人称射击),查看Character Controller page.
If you like, quickly jump to one of the topics covered on this page:
Importing Character Animations
Animation Splitting
Multiple Files
Inverse Kinematics
Inserting Into a Unity Scene
Animating the Character
Animation Blending
Animation Layers
Additive Animation
如果你喜欢,直接跳到一个在这个页面的标题:
输入角色动画
动画片段
多个文件
反向运动
插入Unity场景
使角色做动作
动画混合
动画层
添加动画
You can download an example demo showing pre-setup animated characters here.
你能在here下载演示动画角色设置的例子example demo。
Importing The Animations
输入动画
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.
最方便的制作动画的方法是使用单一的模型包含所有的动画.当输入动画模型,你能定义每部分动画的帧.Unity将自动把动画片段分成单个动作部分,名为动画片段Animation Clips.
For example:
walk animation during frames 1 - 33
run animation during frames 41 - 57
kick animation during frames 81 - 97
例如:
走路动画在帧1 -33
跑步动画在帧41 – 57
踢的动画在帧81 - 97
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.
输入动画你可以直接放置他到工程里的Assets文件夹.Unity将自动输入他.突出显示他在工程视图和编辑输入设置在检视视图.
The Import Settings Dialog for a mesh
一个模型的输入设置对话框
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里动画片段的名字.
起始帧 动画的起始帧.帧数值和创建动画的3D程序使用相同的帧.
终止帧 动画的终止帧
循环帧 如果激活,额外的循环帧插入到动画的最后.这个帧匹配片段的起始帧.如果你想要制作一个循环动画和起始&终止帧不是很准确的匹配时.
Importing Animations using multiple model files
输入动画使用多个模型文件
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.
Unity自动输入所有4个文件并收集所有动画到没有@标签的文件.在上面的例子里, goober.mb将自动建立空闲,跳跃,走路和翻墙的引用.
Importing Inverse Kinematics
输入反向运动
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.
技术:你能使用这个快速测试,如果你的动画重播正常.也可使用卷模式Wrap Mode观察不同的动画行为.特别是循环.
Animating the Character
使角色动起来
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, run 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.
这就是动画合成到来的原因.在Unity你能在同一个角色身上有任意多个动画播放.所有的动画合成或添加到一起产生最终动画.
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.
我们的第一步是使角色平稳合成空闲和走路动画.为了做这个我们使用简单的脚本,我们首先设置卷模式Wrap Mode的动画循环Loop.接着我们关闭自动播放使我们的脚本只有一个正在演奏的动画.
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.
我们的第一个角色动画脚本十分简单;我们值需要一些方法知道我们的动画运行的速度,再减退走路和空闲动画.为了这个简单的测试我们使用pre-setup输入轴.
function Update ()
{
if (Input.GetAxis("Vertical") > 0.2)
animation.CrossFade ("walk");
else
animation.CrossFade ("idle");
}
To get this script running:
使这个脚本运行:
1. Create a javascript using Assets->Create Other->Javascript.
2. Copy & Paste the code into it
3. Drag the script onto the character (It needs to be the same GameObject as the animation)
1. 创建javascript使用Assets->Create Other->Javascript.
2. 复制粘贴代码进入
3. 拖拽脚本到角色(需要有一个同样动画的GameObject)
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.
当你按下运行按钮,且按下向上键角色将开始走路,释放他又回到空闲状态. |
|