【3D技术宅公社】XR数字艺术论坛  XR技术讨论 XR互动电影 定格动画

 找回密码
 立即注册

QQ登录

只需一步,快速开始

调查问卷
论坛即将给大家带来全新的技术服务,面向三围图形学、游戏、动画的全新服务论坛升级为UTF8版本后,中文用户名和用户密码中有中文的都无法登陆,请发邮件到324007255(at)QQ.com联系手动修改密码

3D技术论坛将以计算机图形学为核心,面向教育 推出国内的三维教育引擎该项目在持续研发当中,感谢大家的关注。

查看: 2628|回复: 1

7-2 Enemy Animator Controller 敌人角色控制器

[复制链接]
发表于 2013-10-17 12:24:30 | 显示全部楼层 |阅读模式
学习如何通过动画控制器来驱动巡逻机器人的行为动作。
图片2.jpg

未标题-2.jpg

C#
  1. using UnityEngine;
  2. using System.Collections;

  3. public class AnimatorSetup
  4. {
  5.         public float speedDampTime = 0.1f;              // 速度变化的渐变值.
  6.         public float angularSpeedDampTime = 0.7f;       // 角速度变化的渐变值
  7.         public float angleResponseTime = 0.6f;          // 在角速度下转到另外一个角度需要的时间
  8.         
  9.         
  10.         private Animator anim;                          // 动画控制器组件变量.
  11.         private HashIDs hash;                           // 哈希表变量
  12.    
  13.    
  14.     // 造函数
  15.     public AnimatorSetup(Animator animator, HashIDs hashIDs)
  16.     {
  17.         anim = animator;
  18.         hash = hashIDs;
  19.     }
  20.    
  21.    
  22.     public void Setup(float speed, float angle)
  23.     {
  24.         // 每秒钟转的角度..
  25.         float angularSpeed = angle / angleResponseTime;
  26.         
  27.         // 设置动画控制器中的变量.
  28.         anim.SetFloat(hash.speedFloat, speed, speedDampTime, Time.deltaTime);
  29.         anim.SetFloat(hash.angularSpeedFloat, angularSpeed, angularSpeedDampTime, Time.deltaTime);
  30.     }   
  31. }
复制代码
JS脚本
  1. #pragma strict

  2. class AnimatorSetup
  3. {
  4.     public var speedDampTime : float = 0.1f;        // Damping time for the Speed parameter.
  5.     public var angularSpeedDampTime : float = 0.7f; // Damping time for the AngularSpeed parameter
  6.     public var angleResponseTime : float = 0.6f;    // Response time for turning an angle into angularSpeed.
  7.    
  8.    
  9.     private var anim : Animator;                    // Reference to the animator component.
  10.     private var hash : HashIDs;                     // Reference to the HashIDs script.
  11.    
  12.    
  13.     // Constructor
  14.     public function AnimatorSetup(animator : Animator, hashIDs : HashIDs)
  15.     {
  16.         anim = animator;
  17.         hash = hashIDs;
  18.     }
  19.    
  20.    
  21.     public function Setup(speed : float, angle : float)
  22.     {
  23.         // Angular speed is the number of degrees per second.
  24.         var angularSpeed : float = angle / angleResponseTime;
  25.         
  26.         // Set the mecanim parameters and apply the appropriate damping to them.
  27.         anim.SetFloat(hash.speedFloat, speed, speedDampTime, Time.deltaTime);
  28.         anim.SetFloat(hash.angularSpeedFloat, angularSpeed, angularSpeedDampTime, Time.deltaTime);
  29.     }
  30. }
复制代码
Related documentation
[size=0.875em]Animator Controller (Component Reference)
[size=0.875em]Mecanim Animation System (Manual)
2D Blending


 楼主| 发表于 2014-3-28 11:34:45 | 显示全部楼层
本帖最后由 夜行的猫仔 于 2014-3-28 11:37 编辑

在这里最难理解的是2D动作混合,官方翻译的结果也不是很清楚,在这里做一些解释:

2D Simple Directional 2D简单定向Best used when your motions represent different directions, such as "walk forward", "walk backward", "walk left", and "walk right", or "aim up", "aim down", "aim left", and "aim right". Optionally a single motion at position (0, 0) can be included, such as "idle" or "aim straight". In the Simple Directional type there should not be multiple motions in the same direction, such as "walk forward" and "run forward".
当你的动作表现为不同的方向(就像“向前走”、“向后走”、“向左走”和“向右走”,或“”“朝向上”、“朝向下”、“朝向做”和“朝向右”)时,你可以使用这个混合类型。当然你可以选择“等待”或者“朝向前”作为原点动作。在简单定向模式中应该尽量避免使用相同朝向的动作,比如“向前走”和“向前跑”。
-------------------------------------------------------------------------------------------------------------------------------
以上说的是每一个动作都有自己的唯一方向,比如“向前走”,“向后走”,他们行动方向是一定的但不重复,然后混合他们。不能出现“向前跑”和“向前走”两个同方向的动画。在这种混合模式里可允许有原点不动的动作出现,比如idle,也可以没有这样的动作。
-------------------------------------------------------------------------------------------------------------------------------

2D Freeform Directional 2D自由定向This blend type is also used when your motions represent different directions, however you can have multiple motions in the same direction, for example "walk forward" and "run forward". In the Freeform Directional type the set of motions should always include a single motion at position (0, 0), such as "idle".
这个混合类型同样也用于混合朝向不同的动作,虽然你也可以混合像“向前走”和“向前跑”这样的动作。在自由定向模式下,动作集合一般都应该有一个位于原点的动作,比如“等待”。
-------------------------------------------------------------------------------------------------------------------------------
基本同上,也是动作本身已经确定了运动方向的动画,但是这个模式里允许两个方向相同的动作混合,比如“向前跑”和“向前走”,在此模式下必须要有比如idle这样的原点动作。
-------------------------------------------------------------------------------------------------------------------------------


2D Freeform Cartesian 2D自由笛卡尔坐标Best used when your motions do not represent different directions. With Freeform Cartesian your X parameter and Y parameter can represent different concepts, such as angular speed and linear speed. An example would be motions such as "walk forward no turn", "run forward no turn", "walk forward turn right", "run forward turn right" etc.
这种模式最好使用在你的各个动作间没有明显朝向区别的时候。在使用自由笛卡尔坐标时,你可以在X轴和Y轴上分别使用不同的定义,比如“角速度”和“线速度”。比如这样一些子动作:“向前走动不转弯”、“向前跑动不转弯”、“向前走动转向右”、“向前跑动转向右”等。
-------------------------------------------------------------------------------------------------------------------------------
这种模式适用于不能确定运动方向的动画,参数X,Y可以自由定义含义。比如“线速度”和“角速度”。
-------------------------------------------------------------------------------------------------------------------------------



手机版|小黑屋|3D数字艺术论坛 ( 沪ICP备14023054号 )

GMT+8, 2024-9-28 00:21

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表