Unity动画系统(4)

news2024/9/21 4:29:33

6.3 动画系统高级1-1_哔哩哔哩_bilibili

p333-

声音组件添加

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 AudioSource aud;

    //虚拟按键
    private bool sneak;

    private void Awake()
    {
        ani = GetComponent<Animator>();
        aud = GetComponent<AudioSource>();
    }
    private void Update()
    {
        hor = Input.GetAxis("Horizontal");
        ver = Input.GetAxis("Vertical");
        //获取虚拟按键
        sneak = Input.GetButton("Sneak");

        //if (sneak) {
        //    ani.SetBool("Sneak", sneak);
        //}
        //设置动画参数
        ani.SetBool("Sneak", sneak);


        //只要按下一个方向键,就走
        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);
        }
        //判断当前是否是Locomotion状态
        bool isLocomotion=ani.GetCurrentAnimatorStateInfo(0).IsName("Locomotion");
        if (isLocomotion)
        {
            //判断脚步声音是不是已经开始播放了
            if (!aud.isPlaying) {
                //播放声音
                aud.Play();
            }
        }
        else {
            //停止声音
            aud.Stop();
        }
    }
}

边走路边喊叫 动画分层的应用

Mask

模型正对我们

非人型遮罩------手动勾选

override覆盖上一层的动画

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

public class RobotController : 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 AudioSource aud;

    [Header("喊叫声音片段")]
    public AudioClip shoutClip;

    //虚拟按键
    private bool sneak,shout;

    private void Awake()
    {
        ani = GetComponent<Animator>();
        aud = GetComponent<AudioSource>();
    }
    private void Update()
    {
        hor = Input.GetAxis("Horizontal");
        ver = Input.GetAxis("Vertical");
        //获取虚拟按键
        sneak = Input.GetButton("Sneak");
        shout = Input.GetButtonDown("Shout");
        //if (sneak) {
        //    ani.SetBool("Sneak", sneak);
        //}
        //设置动画参数
        ani.SetBool("Sneak", sneak);
        if (shout) {
            //触发参数shout
            ani.SetTrigger("Shout");


            //播放喊叫声音
            AudioSource.PlayClipAtPoint(shoutClip,transform.position);
        }

        //只要按下一个方向键,就走
        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);
        }
        //判断当前是否是Locomotion状态
        bool isLocomotion = ani.GetCurrentAnimatorStateInfo(0).IsName("Locomotion");
        if (isLocomotion)
        {
            //判断脚步声音是不是已经开始播放了
            if (!aud.isPlaying)
            {
                //播放声音
                aud.Play();
            }
        }
        else
        {
            //停止声音
            aud.Stop();
        }
    }
}

AudioListener挂载在角色身上

参数不能超过1个

IK方向动力学

Inverse kinematics

反应的是一种由手部带到肩部的运动形式,在这个运动中,运动以手部这个自由端为起始,当手部进行运动时会自然的带动固定端肩部的运动。

比如别人拉起你的手

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

public class RobotController : 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 AudioSource aud;

    [Header("喊叫声音片段")]
    public AudioClip shoutClip;

    //虚拟按键
    private bool sneak,shout;

    private void Awake()
    {
        ani = GetComponent<Animator>();
        aud = GetComponent<AudioSource>();
    }
    private void Update()
    {
        hor = Input.GetAxis("Horizontal");
        ver = Input.GetAxis("Vertical");
        //获取虚拟按键
        sneak = Input.GetButton("Sneak");
        shout = Input.GetButtonDown("Shout");
        //if (sneak) {
        //    ani.SetBool("Sneak", sneak);
        //}
        //设置动画参数
        ani.SetBool("Sneak", sneak);
        if (shout) {
            //触发参数shout
            ani.SetTrigger("Shout");
        }

        //只要按下一个方向键,就走
        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);
        }
        //判断当前是否是Locomotion状态
        bool isLocomotion = ani.GetCurrentAnimatorStateInfo(0).IsName("Locomotion");
        if (isLocomotion)
        {
            //判断脚步声音是不是已经开始播放了
            if (!aud.isPlaying)
            {
                //播放声音
                aud.Play();
            }
        }
        else
        {
            //停止声音
            aud.Stop();
        }
    }

    /// <summary>
    /// 播放喊叫声音
    /// </summary>
    public void PlayShoutAudio(float a) {
        Debug.Log(a);
        //播放喊叫声音
        AudioSource.PlayClipAtPoint(shoutClip, transform.position);
    }
}

找到关节

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

public class EthanIKController : MonoBehaviour
{
    private Animator ani;
    [Header("IK动画的开关")]
    public bool ikActive = false;

    [Header("射击敌人的最大角度")]
    public float fireMaxAngle = 100;
    [Header("IK指向的目标")]
    public Transform target;

    [Header("IK指向的目标身高")]
    public float targetHeight = 1.8f;
    private void Awake()
    {
        ani = GetComponent<Animator>();
    }
    private void OnAnimatorIK(int layerIndex)
    {
        //获取玩家指向敌人的方向向量
        Vector3 dir=target.position - transform.position;
        //计算夹角
        float angle=Vector3.Angle(dir, transform.forward);

        if (angle < fireMaxAngle / 2)
        {
            ikActive = true;
        }
        else {
            ikActive = false;
        }

        if (ikActive)
        {
            //设置IK权重
            ani.SetIKPositionWeight(AvatarIKGoal.RightHand, 1);
            //设置IK位置
            ani.SetIKPosition(AvatarIKGoal.RightHand, target.position+Vector3.up*targetHeight);

            //设置眼睛的IK权重
            ani.SetLookAtWeight(1);
            //设置眼睛的IK位置
            ani.SetLookAtPosition(target.position+Vector3.up * targetHeight);

        }
        else {
            //设置IK权重为0
            ani.SetIKPositionWeight(AvatarIKGoal.RightHand, 0);
            //设置眼睛权重为0
            ani.SetLookAtWeight(0);
        }
    }
}

Curve

p341

绑定到一起只需要名称一致

p342

开始慢后期快

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1935850.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

java文本比较解决方案

参考资料 VBA计算页码和行号https://learn.microsoft.com/zh-cn/office/vba/api/word.wdinformation 概述&#xff1a; 最近在做word文档对比的&#xff0c;总结了几种解决方案&#xff0c;记录一下 在java中&#xff0c;常用的文本对比方案有如下几种&#xff1a; 差异比较…

Git分支合并以及分支部分合并 提交记录合并

Git分支合并,以及分支部分合并,提交记录合并 最近工作中用到git分支合并的场景,记录一下. 分支整体合并,合并所有记录 仅合并分支部分代码

【Django】网上蛋糕商城后台-类目管理

1.类目管理列表实现 当管理员进入后台管理后&#xff0c;点击类目管理&#xff0c;向服务器发出请求 path(admin/type_list/,viewsAdmin.type_list), # 处理商品分类管理列表请求 def type_list(request):# 读取分页页码try:ym request.GET["ym"]except:ym 1# 查…

Leetcode算法题(链表的中间节点+返回倒数第k个节点+合并两个有序链表)

题目1&#xff1a; 本题力扣链接&#xff1a;https://leetcode.cn/problems/middle-of-the-linked-list/solutions/164351/lian-biao-de-zhong-jian-jie-dian-by-leetcode-solut/ 思路1&#xff1a;单指针法 首先我们对链表进行遍历&#xff0c;记录链表的总长度N&#xff0c;…

Postgresql导入几何数据的几种方式

postgis方式导入 1.直接使用postgis客户端方式导入 首先&#xff0c;电脑要安装postgresql和对应版本的postgis。然后通过postgis客户端软件连接到postgresql数据库。然后导入。具体详细操作如下所示&#xff1a; 第一步&#xff1a;首先要再postgis中创建数据库 Create da…

【Linux取经之路】Linux常见指令

目录 基本指令 常见指令 1&#xff09;ls —— 对于目录&#xff0c;列出该目录下的所有子目录和文件&#xff1b;对于文件&#xff0c;将列出文件名及其他信息 2&#xff09;pwd —— 显示当前所在的目录 ​编辑 3&#xff09;cd —— 切换到指定路径下 4&#xff09;t…

阿里云DSW实例中安装并运行Neo4J

想尝试使用大模型对接Neo4J&#xff0c;在阿里云DSW实例中安装了Neo4J&#xff0c;却无法通过本地浏览器访问在DSW实例中运行的Neo4J。尝试了改neo4j.conf文件&#xff0c;以及添加专用网络的公共IP地址等方法&#xff0c;均没有成功。最后决定直接在服务器的命令行进行各种Cyp…

如何在 Puppeteer 中运行无头浏览器?

什么是无头浏览器&#xff1f; 我们都知道&#xff0c;用户界面&#xff08;UI&#xff09;是任何软件中最重要的部分。因此&#xff0c;“无头浏览器”的“无头”部分意味着它们确实缺少一个关键元素&#xff0c;即图形用户界面&#xff08;GUI&#xff09;。 这意味着浏览器…

unity渲染人物模型透明度问题

问题1&#xff1a;有独立的手和衣服的模型&#xff0c;但最终只渲染出来半透明衣服 问题2&#xff1a;透明度贴图是正确的但显示却不正确 这上面两个模型的问题都是因为人物模型是一个完整的&#xff0c;为啥有些地方可以正常显示&#xff0c;有些地方透明度却有问题。 其中…

AI大模型,程序员的下一个职业春天

前言 在后疫情时代的经济环境中&#xff0c;各行各业的就业形势变得异常严峻&#xff0c;互联网行业尤甚&#xff0c;裁员潮频发&#xff0c;程序员们的未来似乎笼罩在一层不确定的迷雾之中。曾经&#xff0c;程序员这个职业因其高薪而令人艳羡&#xff0c;但背后的艰辛与压力…

【STM32】LED闪烁LED流水灯蜂鸣器(江科大)

LED正极&#xff1a;外部长脚、内部较小 LED负极&#xff1a;外部短脚、内部较大 LED电路 限流电阻&#xff1a;保护LED&#xff0c;调节LED亮度&#xff08;本实验用面包板为了方便&#xff0c;省去了限流电阻&#xff0c;设计电路时要加上&#xff09; 左上图&#xff1a;低…

ubuntu2204配置anacondacuda4090nvidia驱动

背景 某个机房的几台机器前段时间通过dnat暴露至公网后被入侵挖矿&#xff0c;为避免一些安全隐患将这几台机器执行重装系统操作&#xff1b; 这里主要记录配置nvidia驱动及cuda&anaconda。 步骤 大概分为几个步骤 禁用nouveau配置grub显示菜单install nvidia-driveri…

Linux——远程连接服务器

sshd服务端 ssh客户端 ssh 服务配置 #ssh 服务安装包 openssh-server [rootserver1 ~] # vim /etc/ssh/sshd_config 17 . #Port 22 # 监听端口&#xff0c;默认监听 22 端口 【默认可修改】 18 . #AddressFamily any #IPV4 和 IPV6 协议家族用哪个&#xff0c; any 表示二者…

Python莫兰生死抑制放大进化图

&#x1f3af;要点 &#x1f3af;种群离散时间莫兰生死动态图解 | &#x1f3af;良好混合种群的固定概率 | &#x1f3af;数值求解生成埃尔多斯-雷尼图 | &#x1f3af;计算马尔可夫链的转移矩阵概率 | &#x1f3af;出生死亡动态和死亡出生动态概率无向随机图和有向随机图&am…

【数据结构】树和二叉树——Lesson1

Hi~&#xff01;这里是奋斗的小羊&#xff0c;很荣幸您能阅读我的文章&#xff0c;诚请评论指点&#xff0c;欢迎欢迎 ~~ &#x1f4a5;&#x1f4a5;个人主页&#xff1a;奋斗的小羊 &#x1f4a5;&#x1f4a5;所属专栏&#xff1a;C语言 &#x1f680;本系列文章为个人学习…

一个小问题导致,AI大模型集体翻车?

9.11大还是9.9大&#xff1f; 这两天大家都在说ChatGPT大模型翻车了 &#xff01; 这到底是怎么个事儿呢&#xff1f; 原来是最近有人想ChatGPT等大模型提了一个简单的问题&#xff1a; 9.11 大还是 9.9 大&#xff1f; 答案显而易见&#xff0c;然而众多大模型却给出了错误…

基于JAVA+SpringBoot+Vue的oa系统

✌全网粉丝20W,csdn特邀作者、博客专家、CSDN新星计划导师、java领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ 技术范围&#xff1a;SpringBoot、Vue、SSM、HLMT、Jsp、SpringCloud、Layui、Echarts图表、Nodejs、爬…

【高性能服务器】poll模型

&#x1f525;博客主页&#xff1a; 我要成为C领域大神&#x1f3a5;系列专栏&#xff1a;【C核心编程】 【计算机网络】 【Linux编程】 【操作系统】 ❤️感谢大家点赞&#x1f44d;收藏⭐评论✍️ 本博客致力于知识分享&#xff0c;与更多的人进行学习交流 poll模型 关于sel…

算法-计数质数

题目&#xff1a; 给定整数 n &#xff0c;返回 所有小于非负整数 n 的质数的数量 。 思路&#xff1a; 使用埃式筛法 当n大于等于2时&#xff0c;如果当前遍历的数 i 是质数&#xff0c;那么从 i*i 开始&#xff0c;直到 n 为止&#xff0c;把 i 的倍数都标记为合数 代码&a…

一个关于STM32的DAC输出的遗忘点

众所周知熟练使用HAL库可以帮你解决不少stm32的开发难题&#xff0c;但是是谁让你陷入了这些难题&#xff0c;别问。 如上图所示&#xff0c;正常初始化这个模块后生成代码如下图所示&#xff1b; * DAC init function */ void MX_DAC_Init(void) {/* USER CODE BEGIN DAC_Ini…