Locomotion System(自动适应地形)

Locomotion System

行走,跑动画自动适应地形。全方向,全地形。

By Rune Skovbo Johansen
runevision.com
In collaboration with Unity Technologies ApS
unity3d.com

介绍:

Unity Locomotion System  自动混合关键帧或捕捉动画的走和跑的循环并且调整腿部骨骼的运动来保证脚步能正确地落在地面上。这个系统能调整并改变动画的速率和曲线以任何速率,方向,曲率 ,步幅从一个简单平面到任何倾斜角度的地形。

 Locomotion System 可以被一个添加过骨骼并蒙皮的角色和一些动画使用.  角色至少有一条腿, 而且腿部骨骼至少2. 角色至少要有一个空的动画 (至少有一帧) 至少有一个走或者跑的循环动画.

 Locomotion System 不强制执行任何高级别控制计划 but rather lets you move your character around by any means you desire. Locomotion System 默默关注你角色的 位置, 队列, 速率和旋转速率并在此基础上推论, along with some raycasts onto the ground.

适应性意味着 你可以使用Character Controller, a Rigid Body, 或其他什么来在世界中 移动你的角色.

Locomotion System作不到的是:

  • 物理动画系统或者active animated ragdoll system. 
    此系统未加入物理仿真. 纯粹是运动学的, though it does base the kinematics on some raycasts onto the geometry of the ground.
  • A behavior-based system. 
    此系统无法智能的自动对推,绊,坠落或被打做出反应. 它只是对现有动画进行混合和微调.
  • 可以被所有角色和动画使用的统一完整的系统. 
    这个系统只控制腿. (The whole body is typically implicitly controlled since the system blends together multiple full body animations. However, this can be overridden by the user with specific animations for the upper body, using the usual means available in Unity.)

使用Locomotion System进行,你只需要以下folder Assets > Locomotion System. All other files are not directly part of the Locomotion System and do not have to be included in your project. 当然, 下面的快速指南使用了project folder中额外的一些文件.

 个文档包含以下部分:

  • 快速指南
  • 其他特色
  • 参考
  • 使用条款

快速指南

 快速指南包括以下部分:

  • 基础场景设置
    这里我们设置一个角色使用的场景. 同时添加一个角色和一些scripts来让我们能够使用方向键来移动角色.
  • Locomotion System 设置
    现在我们开始设置 Locomotion System 让它开工.
  • 添加 Running 
    我们添加一个跑得动画循环到Locomotion System这样角色又能走又能跑.
  • 使用更多的动画 
    这里我们添加左右扫射动画并转身向后,来提高真实性.

基础场景设置

这个快速指南假定你使用项目包中的 Hero 角色.

  • 放置 Hero 模型到场景中. Hero模型位置在 Assets > Characters > Hero Artwork > Hero. 设置位置为(0, 0.1, 0) and scale to (0.01, 0.01, 0.01).

你可以一使用任何方法来移动character around. 这个快速指南中 我们将使用一个标准 Character Controller 组件来控制 collisions(碰撞)和一些 script components(脚本组件)来控制input(输入)和移动。

  • 在角色脚下放置一个带碰撞(collider)的地板.  点击 GameObject > Create Other > Cube. 调整位置和大小比例,上张地板贴图. 同时打盏灯.
  • 添加一个 Character Controller 组件 来代替处理角色和物体的碰撞. 调整大小参数来匹配角色.
  • 添加一个 Normal Character Motor 脚本(通用角色驱动) (脚本位置Assets > Character Controller Scripts > NormalCharacterMotor) 处理角色的运动.
  • 添加一个Platform Character Controller脚本(角色平台控制)(脚本位置 Assets > Character Controller Scripts > PlatformCharacterController) 处理角色的输入(input).

(注意上面三个组件和脚本都不是Locomotion System. 你必须用自己的解决方案来替代.)          

确定 Character Controller 让角色不要碰到地面但同时也不能看着好像悬浮在空中 .   Play 模式下调试 .
Locomotion <wbr>System(自动适应地形)


 
  • 点击Play 按钮. 你现在可以使用方向键移动 Hero 角色, 但只是移动而角色的步伐是不动的.

设置Locomotion System

让我们开始设置  Locomotion System.

  • 检查Unity  menu bar à   Tools > Locomotion Initialization但别用它仅仅检查即可. 你后面会用到这个菜单. 如果菜单栏里没这项, 肯定是哪里出了问题. 这个菜单是由  Assets > Locomotion System > Editor下的脚本(script) LocomotionEditorClass.cs生成的。
  • 首先, 现在角色应该只有一个动画组件( component) (如果你的角色一个动画组件也没有, 应该是哪里出错了). Uncheck the option Play Automatically.
  • 添加一个Leg Controller 脚本组件(script component) 给角色(位置在Assets > Locomotion System > LegController). It must be on the same game object that has the Animation component.
设置 Leg Controller   组件里的   Ground Plane Height    .   一个绿色的   gizmo 十字将出现在角色的脚下 .   Hero 角色的地平面高度是 0.
Locomotion <wbr>System(自动适应地形)

注意这个高度 measured in units prior to applying the角色的移动值. 这可以确定以后你的角色能够使用不同的 位置,旋转和缩放比例 而同时不用改变 Leg Controller 的变量值.

  • 1.    拖拽角色的idle animation 到变量(variable)  Grounded Pose. 有一个方法可以快速从 Project窗口拿到动画(animations)  点击动画组件(Animation component)的动画片断            (animation clip)  Animation 变量(variable). Hero 角色的idle animation 名称是 Idle1.
  • 2.    根骨骼(Root Bone) 是动画层级的基础骨骼.  如果你不自己单另设定的话默认情况下它被设置为第一条腿髋骨( hip bone) 的父骨骼.
  • 3.    点击小三角展开Leg Controller 组件(component)中的Legs 扩展区. 这个扩展区里面包含所有Leg的设置数据(setup data).

·       4.   点击 Add Leg 按钮. 然后点击小三角展开 Leg 1的属性栏看它的设置, 然后做下面的:

Locomotion <wbr>System(自动适应地形)

  • 找到角色骨骼层级中的髋骨 hip bone (upper leg bone)并拖拽到Hip 变量框中 .  Herocharacter it is Hero > Reference > Hips > LeftUpLeg (left leg控制大腿旋转).

     找到角色骨骼层级中脚踝骨ankle bone (foot bone) 并拖拽到Ankle 变量框中.   Hero character it is Hero > Reference > Hips > LeftUpLeg > LeftLeg > LeftFoot (left leg).

    注意 Ankle变量实际控制脚的旋转. 人类是用脚踝控制脚的旋转, 但有些动物的踝骨在腿部的位置比较高, 这个时候控制脚的骨骼 (爪或者蹄)将被放进Ankle变量来代替踝骨.

    如果角色有脚趾 toe bone (或脚尖 toe tip bone) 那么拖拽它到Toe变量框中. 其他情况下则拖拽最腿部最低层级的骨骼到 Toe 变量框, 即使最低时 ankle bone (foot bone) 也可以再拖拽进Toe 变量框即可.

     设置脚的长,宽(Width, Length), 和位移( Offsets). 一个绿色的 gizmo 方块 会出现在脚周围,它可以用来校验大小和位移是否正确. 同样这些尺寸are in unitsprior to scaling.
    Locomotion <wbr>System(自动适应地形)

     

    ·                     第一条腿调整好后, 点击 Add Leg 按钮添加另外一条腿. 剩下这条腿会拷贝前一条腿的脚的长,宽(Width, Length), 和位移( Offsets)数据, 如果两条腿近似你就不用再调这些数值了.

    • 注意 Hip, Ankle and Toe 的数值你还是必须自己设置. 方法和前面那条腿一样.
    • 点击小三角展开Leg Controller组件(component) Source Animations扩展区.

    Leg Controller组件(component) Source Animations扩展区包含所有Locomotion System将要处理的动画.通常包括:

    • 所有走和跑的动画.
    • 角色脚落在地面上时的所有动画.
    • 不包括跳起和腾空时的动画.
    • 不包括上半身动画 upper body (这样它们不会影响到腿部).

    在这个快速指南中我们将首先用几个动作快速测试  Locomotion System  来看看怎么样.然后我们将添加更多动作并看看角色移动有什么改进.

    • 如果你使用的是 Hero 角色,跟着下面作:
      • Under the group 没有使用, 点击小三角展开 Not Used(by Locomotion System)扩展栏,钩选Idle1  WalkForward 动作右边的  checkboxes  .
      • 点击下面的 Move Selected选择 New Group.
    动作被移动到一个new group名称是MotionGroup1.我们将其改名为locomotion.
    Locomotion <wbr>System(自动适应地形) 
    • Idle1动作的Motion Type WalkCycle 更改为 Grounded.
    • 展开 WalkForward 动作并钩选 Use Backwards.
    • 点击Initialize按钮.
    • 增加一个腿部动画脚本组件( script component )给角色 (脚本位置 Assets > Locomotion System > LegAnimator).
      • 设置角色的 Layer Player. 这并不是系统要求的 , 但是你需要确定 无论如何腿部动画组件里的可变Ground Layers不包含角色自己. 这也是为什么 raycasts used by the Locomotion System don't hit the collider of the character itself.
    • 点击 Play button.使用方向键移动角色.

    你可以做一个有不同倾斜表面的场景里面有大大小小的箱子和台阶, 有两个重要参数能够决定角色腿能抬多高 1. Character Controller 组件里的Step Offset    2. Leg Animator 组件里的Max Step Height .

    Locomotion <wbr>System(自动适应地形)

    如果你想让角色 不仅能向前走而且可以左右横移并后退, 那么你需要增加一个 Aim Look Character Controllerscript (脚本位置 > Character Controller Scripts >AimLookCharacterController).

    注意这个脚本不是Locomotion System自带的 , 而且你可以简单的通过控制角色的移动和旋转自己写脚本来控制走动方向. Aim Look Character Controller需要你在输入设置中(input settings)定义两个新的轴向( axes) 名称是(水平)Horizontal2 (垂直)Vertical2  .修改位置在

     menu Edit > Project Settings > Input. 举例来说你可以让方向键控制老的轴向 ,新轴向用 A, D  S, W控制.

    添加跑动动作

    我们现在的角色只是用了一个(原地空闲) idle animation 和一个(走动循环) walk cycle animation. 走动看起来不完全真实. 这主要是由于角色走动速率和动画片段的native speed 速率不匹配.

    • 点击Leg Controller component组件, 展开Source Animations sectionWalkForward animation settings. 注意展开的有一个只读变量名字叫Native Speed.
    • Locomotion <wbr>System(自动适应地形)

       Native Speed变量就是匹配给定walk cycle (走动循环)的最佳速率.

      Hero 角色WalkForward走动循环的Native Speed 大约为 0.7. 这意味着 0.7这个速度值是WalkForward走动循环的最佳值。

      回到Normal Character Motor 脚本组件设置 Max Forward Speed  0.7, and the same for the other speeds.

      • 点击 Play button. 现在走动看起来更真实了, 但还是太慢!

      始终确保你制作的动画真实的和你需要角色在游戏中走动的速度相匹配.  Locomotion System 是怎么确定 walk run cycles native speed 它分析脚在最贴近地面时移动的多快. 在高质量的动画中, 脚步移动总是保持持续的速度当落在地面时. This is because for a given walk or run cycle the ground should be moving with a constant speed relative to the character.

      • 我们让角色跑得更快一点! 展开 Not Used 列表,选择名字为 RunForwardanimation clip(动画片断)   并将其移动到先前我们创建的名为locomotionmotion group动作组里. 你最好钩选RunForward animatonAlso Use Backwards项目.
      • 点击 Initialize 按钮.
      • 找到RunForward 动作 Native Speed  然后把这个值赋予 Normal Character Motor组件中的相应值.
      • 点击 Play 按钮. 角色现在可以跑了 . (看起来不完全算跑. 但不管怎么样比走快多了.)

      注意当你在跑动中突然返身向后, 角色会自动转身. 角色移动方向的改变比角色面向方向的改变要快  . While the Normal Character Motor is responsible for this behavior, it is the Locomotion System that makes it look good. This is a thing the Locomotion System handles well and which can improve the realism of walking and running a lot.在现实中, 人在改变运动方向之初身体并没有完全转过来!

      如果只用键盘, 可以按 shift键盘来加快脚步. 这是 Platform Character Controller脚本给角色添加控制的一个功能(注意要钩选default is walk否则就是减慢脚步了).  由于WalkForward 动作的native speed    RunForward 动作native speed25%, 试着设置Platform Character Controller Walk Multiplier 值为0.25.

      使用更多的动画:

      迄今为止我们使用了3个动画. 如果想让侧面跑和向后跑的动作更真实, 你可以在条件允许的情况下添加更多的动作. (You can skip this section if you want.)

      • Leg Controller 组件Source Animations项中, 关闭  WalkForward RunForward 动画的Also Use Backwards功能.
      • 展开 Not Used 列表然后选择以下动画片段:
        • WalkBackward
        • RunBackward
        • WalkStrafeLeft
        • RunStrafeLeft
        • WalkStrafeRight
        • RunStrafeRight
      • 将选定动画片段放入早先建立的 locomotion motion group .
      • 然后点击 Initialize 按钮. 再点击 Play.

      角色现在各个方向的移动都看起来真实了.

      系统通常会自动以合适的权重来融合动作. 当没有可用的后退动画时 我们通常会给前进动画打开Also Use Backwards选项, 即便角色被预期不会后退.系统将使用前进动画回放来假定它是另一个额外的 动画片段而这对所有方向的动画融合都有改善.Also Use Backwards功能打开时strafe left也可以模拟  strafe right.

      这就是快速指南的大致内容. 下一个章节不是作为教程来写的 而是将深入Locomotion System另外一些特性的细节 ,这些内容将有助于将系统整合进你的游戏并进一步增加真实性.

      Additional Features附加特性

      此章节包括以下部分:

      • Blending and Cross Fading (融合与交叉)
        This part is about how to interface with the Locomotion System from your own scripts. An example script is described which can be used to control waiting and jumping animations.  
        这部分是关于如何让 Locomotion System和你自己的脚本结合的。 一个范例脚本演示了如何控制等待和跳跃动画。
      • Leaning (倾斜)
        通过让角色在陡斜的地面走动  加速跑动时如何倾斜身体来进一步提高真实性.
      • Ground Hugging for Non-Bipeds (非两足动物的地面适配)
        多足动物下肢支撑身体的模式和人或者其他两足动物是不同地.   Locomotion System 有两个简单的设置来控制它.

      Blending and Cross Fading(融合与交叉)

      目前为止Locomotion System 已经能够控制走和跑的所有时间. 这一节我们将进一步研究两个不同动画的融合与交叉以便角色能够做 更多的动作而不仅仅是站立,走动和跑.

       Locomotion System  使用了一个 motion groups的概念. 一个 motion group是一个能被完整控制的 动作组. motion group 可以包含一个或多个Walk Cycle类型的动画 和任意一个Grounded类型的动画. 一个动作组不应该包含相同速率的动画. 这是为什么只能至多包含一个grounded 类型的动画, 因为grounded动画的速率( velocity)总是为0.

      Motion groups can be used to specify groups of animations with the same style. 例如, 你可能有一个组包含 一个普通空闲站立,,和跑的动画, 另一个组包含一个卑怯的空闲站立和跑的动画.motions groups中个别单独动画的权重自动受系统约束时,系统可以用脚本控制哪个动作组起作用.

      上一节我们使用"locomotion"动作组在 Locomotion System中设置所有动画  . "locomotion" 这个名字只是个范例. 你完全可以起任意一个名字.

      如果你写自己的脚本Locomotion System 能够 blended in and out by using a motion group name as an animation name,  例如:

       
      animation.CrossFade("locomotion",0.5f);

      This will fade the Locomotion System in over half a second. It will also automatically be faded out if other animations are cross faded in, just the same way as it works with other animations. You can also set the weight
      这将淡入淡出Locomotion System超过半秒。如果其它动画混合进来它也会自动淡出。


      directly the same way as for other animations:

       
      animation["locomotion"].weight = 0.8f;

      Blending, crossfading, and weights generally work the same as for other animations. However, the Locomotion System is not compatible with the functions CrossFadeQueued and PlayQueued. Those functions can

      混合,融合,并且权重和其它动画一样作用。可是Locomotion System 不适合CrossFadeQueued and PlayQueued 功能。这些功能能够被只作用于上半身的动画使用;但不适用于Locomotion System


      still be used on animations that only affect the upper body, but they should not be used with animations controlled by the Locomotion System. Also note that the individual animations in a motion group should not be

      控制的那些动画。另外请注意:一个动作组中的独立动画无法用手动控制。Locomotion System 对此是排斥的。
      handled manually; the Locomotion System will take care of those exclusively.

      不在动作组(motion groups)中的动画只有两种:   Locomotion System控制的和不为 Locomotion System控制的.

      • 添加一个动作进Locomotion System但不放入动作组(motion groups, 只需要选择动作然后点击Move Selected To 然后选择Ungrouped e. 你可以像平时一样设置动画的权重, 然后脚步会正确的落在地面上.
      • 使用一个没有被 Locomotion System控制的动画 (也就是. 也就是在 Not Used 列表下的), 方法和你通常做法没什么不同. 当这些动画被使用时, Locomotion System 的效果会blended down 腿部不在强制适配地面了. 这个很有用比如说跳起腾空的动作.

      脚本 JumpAndIdle.cs 展示了跳跃时如何融合进一个跳的动画,并且and how to fade to an extended idle animation 当角色原地停止一段时间后 . Try it out:

      • 选择Not Used列表中的动画 Idle2并移动到 Ungrouped.(记得把模式改为Grounded
      • 记住点击Initialize 按钮.
      • 添加 Jump And Idle 脚本组件给角色。 脚本位置在 Assets > Character Controller Scripts > JumpAndIdle.
        • 拖拽动画片段 AimIdle  到变量Jumping Animation.
        • 拖拽动画片段Idle1     到变量   Idle Animation.
        • 拖拽动画片段Idle2   到变量    Waiting Animation.

      Hero 角色很不幸没有一个起跳动画所以我们把 AimIdle动画暂时拿来做个演示.

      • 点击 Play.

      试着按空格键 Space. (这需要 input settings 有一个 input 命名为 Jump 并且映射给 space key.)   站住停止几秒你会看见角色伸手挠头.

      Leaning倾斜

      当人加速启动或跑动时, 身体会朝前进的方向倾斜. 这包括从站立转换到走身体会轻微前倾, 或急转弯时人体会侧倾.

        Locomotion System并不支持适用特殊动画来表现加速 accelerating.     然而,   Locomotion System 可以开启一个基于加速度的程序倾斜。

      Leg Animator组件中,  Accelerate Tilt Amount(加速倾斜数量)  Accelerate Tilt Sensitivity(加速倾斜灵敏值)这两个参数控制基于加速度的倾斜. tilt amount(倾斜数量)是简单增加;  默认值是0.02  但灵敏值为0时它是不起作用的. 倾斜灵敏值是对应于速度的灵敏值. 这个数值高那么即使跑动速度不快身体也倾斜的利害,数值地的时候只有跑到最快身体才会倾斜一点. 这个灵敏值的起始默认数值设为10 比较好,divided by the 角色移动的最大速度.
      Locomotion <wbr>System(自动适应地形) 

      在现实世界中,倾斜不仅仅发生在加速时,也发生在上下斜坡时(这里假定角色是两条腿).   Locomotion System 有两个设置来控制攀爬斜坡太极时的倾斜.

      Leg Animator 组件中,  设置项 Climb Tilt Amount Climb Tilt Sensitivity控制基于加速度的倾斜. tilt amount(倾斜数量)是简单增加; 默认值为0.5但灵敏值为0时它是不起作用的. climb tilt sensitivity是基于速度的敏感度。
    • Locomotion <wbr>System(自动适应地形)
      Ground Hugging for Non-Bipeds(非两足角色的地面适配)
    • 以下部分懒的翻译了Locomotion <wbr>System(自动适应地形)4足动物或者章鱼之类的,大家看英文文档把。反正内容不多。
  • http://blog.sina.com.cn/s/blog_409cc4b00100qy0i.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值