Unity Mecanim动画系统 之 动画混合树(Blend Trees)的简单使用

目录

Unity Mecanim动画系统 之 动画混合树(Blend Trees)的简单使用

一、简单介绍

二、官网的 Blend Trees 的解释

1)Blend Trees

2)1D Blending

3)2D Blending

三、注意事项

四、效果预览

五、实现步骤

六、关键代码


一、简单介绍

Unity中的一些基础知识点。便于后期开发使用。

Unity动画系统,也称为“Mecanim”,提供了以下功能:

  • 简单的工作流程,设置动画的所有元素,包括对象,角色和属性。

  • 支持导入外部创建的动画片段和使用内置动画编辑器制作的动画片段。

  • 人型动画重新定位,动画角色的运动控制可以被所有的角色模型共享,即角色的外观(SkinedMesh)和运动(Animator)是分离的,它们互相组合之后形成最终的动画。

  • 用于编辑动画状态的的简化工作流程,即动画控制器。

  • 方便预览动画片段,以及片段之间的插值过渡。 这使得动画师可以独立于程序员工作,在不运行游戏的情况下,可以对原型和预览动画进行预览。

  • 管理动画与可视化编程工具之间的复杂交互。

  • 不同的身体部位可以使用不同的动画逻辑控制。

  • 动画的分层和掩蔽功能。

状态机之中的状态不仅可以是单个剪辑,也可以是一个混合树。构建和编辑复杂的状态机和混合树,以便完全控制的角色如何运动。Unity编辑器提供强大的工具,用于分割、创建循环和从导入的动画文件中提取轨迹。然后可以把这些动画短片用作一个多层混合树的叶子,或者作为分层状态机中的一种状态。混合树让您只使用几个动画剪辑就能创建各种各样的运动。在混合树编辑器中,您可以定义混合参数并在3D视图中预览混合动画。混合树和动画剪辑一样,可以用作分层状态机中的状态。

动画混合树,就是多个动画切换更自然和谐,并且使得脚本控制更加容易,本节简单的介绍,混合树 Blend Trees 的使用。

二、官网的 Blend Trees 的解释

1)Blend Trees

A common task in game animation is to blend between two or more similar motions. Perhaps the best known example is the blending of walking and running animations according to the character’s speed. Another example is a character leaning to the left or right as it turns during a run.

It is important to distinguish between Transitions and Blend Trees. While both are used for creating smooth animation, they are used for different kinds of situations.

2)1D Blending

The first option in the Inspector
 of a Blend Node
 is the Blend Type. This drop-down is used to select one of the different blend types that can blend according to one or two parameters. 1D Blending blends the child motions according to a single parameter.

After setting the Blend Type, the first thing you need is to select the Animation Parameter that will control this Blend Tree. In this example, the parameter is direction which varies between –1.0 (left) and +1.0 (right), with 0.0 denoting a straight run without leaning.

3)2D Blending

The first option in the Inspector of a Blend Node is the Blend Type. This drop-down is used to select one of the different blend types that can blend according to one or two parameters. The 2D blending types blends the child motions according to two parameters.

The different 2D Blend Types have different uses that they are suitable for. They differ in how the influence of each motion is calculated.

(1)2D Simple Directional: 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”.

(2)2D Freeform Directional: 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”.

(3)2D Freeform Cartesian: 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.

三、注意事项

1)此Animator组件中的Apply Root Motion选项如果我们勾选了的话,当播放动画时是通过动画运动的幅度来改变角色的Transform的,如果我们不勾选,我们就可以用脚本设定此角色的Tranform。

四、效果预览

五、实现步骤

1、导入一个带动画的模型

2、新建 Animator Controller ,在控制器添加一个 Blend Tree

3、双击Blend Tree,进去编辑设置

4、点击 Blend Tree,设置 Blend Type

5、添加自己要控制的 Parameters (在 Animaor Controller 中构建的参数)

6、添加自己需要控制的动画

7、因为我们这里是要控制人物向前走,跑,左转右转,所以首先 Compute Positions 选择 Velocity XZ

8、然后,参考动画 左转右转 使用 角度控制更合适

9、返回 Blend Tree ,在 Compute Position 选择 X Position From 的 Angular Speed(Deg)

10、再根据需要,合理调整一下一些参数数值

11、退出 Blend Tree 编辑

12、新建一个脚本,来控 Animator Controller 的参数,来控制动画切换

13、把脚本,挂载到场景模型上

14、运行效果,如下

15、动画参数,混合树数量,根据自己需要调整

六、关键代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Player : MonoBehaviour
{// 动画控制机private Animator anim;// 参数 转为 StringToHash IDprivate int speedForwardId = Animator.StringToHash("SpeedForward");private int turnLeftRightId = Animator.StringToHash("TurnLeftRight");// Start is called before the first frame updatevoid Start(){// 获取 动画控制机anim = GetComponent<Animator>();}// Update is called once per framevoid Update(){if (anim !=null) {// 根据混合数的数值上下限设置后面的 乘以比例anim.SetFloat(speedForwardId,Input.GetAxis("Vertical")*4.15f);anim.SetFloat(turnLeftRightId, Input.GetAxis("Horizontal")*122.8f);}}
}

Unity Mecanim动画系统 之 动画混合树(Blend Trees)的简单使用相关推荐

  1. Unity Mecanim动画系统 之 动画层(Layers)和 动画遮罩(Avatar Mask)的简单使用

    Unity Mecanim动画系统 之 动画层(Layers)和 动画遮罩(Avatar Mask)的简单使用 目录 Unity Mecanim动画系统 之 动画层(Layers)和 动画遮罩(Ava ...

  2. Unity3D Mecanim 动画系统骨骼动画问题解决方法

    Unity3D Mecanim 动画系统骨骼动画问题解决方法 参考文章: (1)Unity3D Mecanim 动画系统骨骼动画问题解决方法 (2)https://www.cnblogs.com/al ...

  3. 【Unity入门计划】Unity2D动画(2)-脚本与混合树实现玩家角色动画过渡

    目录 1 玩家角色移动伴随的简单动画 1.1 行走 1.2 停留 1.3 攻击敌人(触发型) 1.4 受伤(触发型) 1.5 跳跃 1.6 下蹲 2 动画间的过渡 3 过渡的判断逻辑 3.1 行走与停 ...

  4. 【Unity3D】Unity3D Mecanim动画系统骨骼动画问题解决方法

    这几天开始做游戏中跟动画相关的部分了,此次新项目我们决定一次从新开始,就是能用新的东西就都用新的东西,没有必要总是把自己局限在之前的认知里头,所以此次我们大胆而又现实的采用了Unity 4.x版本新增 ...

  5. UE4源码阅读_骨骼模型与动画系统_动画流程

    0. 写在前面 本文为个人学习的笔记整理,如有错误,望不吝指出. 本篇粗略的描述UE4中每帧动画计算的主流程,该流程涉及的相关代码,因为动画设置的多样性,还有相当多的分支代码. 本篇只描述角色跑起一个 ...

  6. unity新动画系统之动画层和动画遮罩

    这一节来说说unity动画层layer和遮罩avatarMask: weight 权重,对应着这一层动画在所有层动画中所占的比例.以上图来说明,new layer中的weight为0,模型的动画效果就 ...

  7. Unity 动画系统 03 动画间的连接问题

    这是我做的rpg游戏的法师角色的动画状态机 用moveSpeed参数控制人物是否在移动,如下图 拖入两个动画后右键单击一个动画,make transition来建立动画间的联系,也就是图中带箭头的白色 ...

  8. Unity动画系统详解5:BlendTree混合树是什么?

    摘要:"Animator中有一个功能,用来解决多个动画之间的混合,经常用于移动动画之间的混合,这个功能叫做BlendTree,混合树." 洪流学堂,让你快人几步.你好,我是跟着大智 ...

  9. unity velocity_Unity动画系统详解5:BlendTree混合树是什么?

    摘要:"Animator中有一个功能,用来解决多个动画之间的混合,经常用于移动动画之间的混合,这个功能叫做BlendTree,混合树." 洪流学堂,让你快人几步.你好,我是跟着大智 ...

最新文章

  1. Android 2D游戏引擎AndEngine配置环境
  2. python剑指offer 包含min函数的栈
  3. ps抠头发插件_PS顶级抠图插件Topaz Mask AI 1.0.2!支持2020Win/Mac,转发领取
  4. 手机pdf文件转语音_没有电脑也能处理PDF文件,手机里的这个功能太强大!
  5. Python实例讲解 -- 图片处理
  6. mysql select不走索引_避免写出不走索引的SQL, MySQL
  7. Pytorch常用总结(持续更新...)
  8. 学以致用一 安装centos7.2虚拟机
  9. 《算法导论》.pdf
  10. JS超好用的免费混淆工具
  11. CListCtrl和CImageList关联的图片删除问题
  12. 终端模拟器怎么用android命令大全,终端模拟器命令大全apk下载-终端模拟器刷入recovery手机版下载V1.0.70安卓最新版-西西软件下载...
  13. UT单元测试总结实践篇
  14. python表格多列合并_python怎么批量合并excel表格
  15. python 扫码签到_python3之51cto自动定时签到
  16. python根据关键字爬取微博_Python 超简单爬取微博热搜榜数据
  17. 法语学习(1)--入门资料推荐
  18. 如何使用ANSYS workbench导出最清晰的图的步骤
  19. 是谁毁了GIS应届毕业生
  20. Linux中的source

热门文章

  1. 最新自动化专业毕设题目选题推荐
  2. 2023最新自动化毕业设计题目选题大全
  3. hyit 第二届ctf校赛wp
  4. Duplicate class org.apache.commons.logging.Log found in modules jetified-commons-logging-1.1.3解决方法汇总
  5. SkyWalking--OAL--使用/教程/示例
  6. base、热区、_blank、锚点
  7. PbS硫化铅量子点;CdS硫化镉量子点修饰TiO2纳米棒阵列;牛血清白蛋白(BSA)修饰Ag2S量子点的定制服务
  8. SPI总线中CS信号的处理
  9. 【科技百咖】人大金仓:先定一个小目标,比如做中国No.1的数据库
  10. 记录实际邓白氏申请(可加急)