当前位置: 首页 > news >正文

Unity动画系统(3)---融合树

6.1 动画系统基础2-6_哔哩哔哩_bilibili

Animator类

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EthanController : MonoBehaviour
{
    private Animator ani;
    private void Awake()
    {
        ani = GetComponent<Animator>();
    }

    private void Update()
    {
        动画参数名称可以转换为一个ID【int】
        //int id = Animator.StringToHash("CanMove");
        //Debug.Log("ID"+id);
        设置后读取动画参数
        //ani.SetBool("CanMove",true);
        [使用HashID进行参数的设置或读取,效率更高]
        //ani.SetBool(id, true);

        //ani.SetFloat
        //ani.GetFloat
        //ani.SetInteger
        //ani.GetInteger
        //ani.SetTrigger
        //ani.SetTrigger [触发参数]

        ani.SetFloat("ShoutPlaySpeed", 2);
        ani.SetFloat("ShoutPlaySpeed",2,0.5f,Time.deltaTime);

        //按下方向键左键
        if (Input.GetKeyDown(KeyCode.LeftArrow)) {
            ani.SetBool("CanMove", true);
        }

        if (Input.GetKeyDown(KeyCode.RightArrow)) {
            ani.SetBool("CanMove", false);
        }

        if (Input.GetKeyDown(KeyCode.Space)) {
            ani.SetTrigger("Shout");
        }
        if (Input.GetKey(KeyCode.S)) {
            //设置喊叫动画的播放速度,有0.5s过渡时间
            ani.SetFloat("ShoutPlaySpeed",2,0.5f,Time.deltaTime);
        }
        //获取当前动画状态信息
        AnimatorStateInfo info = ani.GetCurrentAnimatorStateInfo(0);

        Debug.Log(info.IsName("Idle"));

        Debug.Log("shortNameHash:"+info.shortNameHash);

        Debug.Log("Idle:" + Animator.StringToHash("Idle"));

        //判断当前播放的动画状态是不是Idle
        //if(info.IsName("Idle"))【通过名字判断】
        //if(info.IsTag("Idle"))【通过标签判断】

        if (info.shortNameHash == Animator.StringToHash("Idle")) {
            //【通过hashid判断】【高效】
        }
    }
}

p320-p328未学习

p329(5:35)

融合树参数类型必须是float

时间缩放播放速度

根据动画参数计算阈值

方向不同时使用2D融合类型

一般使用speed and angular speed

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RobotAnimationController : MonoBehaviour
{
    [Header("平滑过渡时间")]
    [Range(0,3)]
    public float dampTime = 3f;


    [Header("移动速度")]
    public float speed = 3f;

    [Header("转身速度")]
    public float turnSpeed = 10f;
    //虚拟轴
    private float hor, ver;
    //动画组件
    private Animator ani;

    private void Awake()
    {
        ani = GetComponent<Animator>();
    }
    private void Update()
    {
        hor = Input.GetAxis("Horizontal");
        ver = Input.GetAxis("Vertical");

        //只要按下一个方向键,就走
        if (hor != 0 || ver != 0)
        {
            //设置Speed,角色动起来
            ani.SetFloat("Speed", 5.6f, dampTime, Time.deltaTime);
            //将向量转换成四元数
            Quaternion targetQua = Quaternion.LookRotation(new Vector3(hor, 0, ver));

            //lerp过去
            transform.rotation = Quaternion.Lerp(transform.rotation, targetQua, Time.deltaTime * turnSpeed);
        }
        else {
            //停下来
            ani.SetFloat("Speed", 0f);
        }       
    }
}

http://www.lryc.cn/news/402278.html

相关文章:

  • sqlalchemy.orm中validates对两个字段进行联合校验
  • 【ROS2】高级:解锁 Fast DDS 中间件的潜力 [社区贡献]
  • VirtualBox虚拟机与主机互传文件的方法
  • 访问控制系列
  • 【BUG】已解决:ModuleNotFoundError: No module named ‘cv2’
  • 成都亚恒丰创教育科技有限公司 【插画猴子:笔尖下的灵动世界】
  • gite+picgo+typora打造个人免费笔记软件
  • 只用 CSS 能玩出什么花样?
  • Linux C++ 056-设计模式之迭代器模式
  • 【Elasticsearch7.11】reindex问题
  • nginx代理缓存
  • [React 进阶系列] useSyncExternalStore hook
  • Linux C++ 055-设计模式之状态模式
  • 景联文科技构建高质量心理学系知识图谱,助力大模型成为心理学科专家
  • 【数学建模】——数学规划模型
  • 卸载linux 磁盘的内容,磁盘占满
  • LeetCode-随机链表的复制
  • axios 下载大文件时,展示下载进度的组件封装——js技能提升
  • Linux: network: device事件注册机制 chatGPT; notify
  • 【ROS2】测试
  • 别卷模型,卷应用:从李彦宏的AI观点谈起
  • 数据库(Database,简称DB)介绍
  • Redis五种常用数据类型详解及使用场景
  • Postman API测试覆盖率:全面评估指南
  • C++--find
  • JavaWeb入门程序解析(Spring官方骨架、配置起步依赖、SpringBoot父工程、内嵌Tomcat)
  • mysql命令练习
  • AI绘画Stable Diffusion 零基础入门 —AI 绘画原理与工具介绍,万字解析AI绘画的使用教程
  • jenkins添加ssh证书
  • C++--accumulate介绍