位置: 编程技术 - 正文

Unity3D 里IK手柄的用运(unity手柄圆盘)

编辑:rootadmin
实现功能:1.当点击鼠标右键,左右手扶住武器, 进入射击状态 2.再次点击鼠标右键,武器消失,取消射击状态 解决方法: ①将武器放置为头部的子物体 ②在武器体下面设置3个子空物体,分别作为子弹出射点,左手放置位置,右手放置位置。 void OnAnimatorIK(int layerIndex) { float aim = animator.GetFloat("Aim"); if(layerIndex == 0){ if(target!=null) { //设置武器瞄准目标的位置 Vector3 tPosition = target.transform.position; tPosition.y = tPosition.y &#; 0.2f*(tPosition- animator.rootPosition).magnitude; animator.SetLookAtPosition(tPosition); animator.SetLookAtWeight(aim,0.5f,.5f,0.0f,0.5f); //设置武器消失与出现 if (bazoo != null) { float fire = animator.GetFloat("Fire"); Vector3 pos = new Vector3(-0.f, -0.f, -0.f); Vector3 scale = new Vector3(0.2f, 0.f, 0.2f); pos.x -= fire * 0.2f; scale = scale * aim; bazoo.transform.localScale = scale; 当aim&#;为0时,大小变成了0,武器就消失了 // bazoo.transform.localPosition = pos; } } } if (layerIndex == 1 ) { //设置左手IK权重 if(leftHand!=null) { animator.SetIKPosition(AvatarIKGoal.LeftHand,leftHand.transform.position); animator.SetIKPositionWeight(AvatarIKGoal.LeftHand,aim); } if(rightHand!=null) { //设置右手IK权重 animator.SetIKPosition(AvatarIKGoal.RightHand,rightHand.transform.position); animator.SetIKPositionWeight(AvatarIKGoal.RightHand,aim); } } } //发射子弹 //射击逻辑 if(Input.GetButton("Fire1")&&fire<0.f&&aim>0.f) { animator.SetFloat("Fire",1); if(bullet!=null&&FirePosition!=null) { GameObject newBullet = Instantiate(bullet,FirePosition.transform.position,Quaternion.Euler(0,0,0)) as GameObject; Rigidbody rb = newBullet.GetComponent<Rigidbody>(); if(rb!=null) { rb.velocity = FirePosition.transform.TransformDirection(Vector3.forward*); } } } 源代码:using UnityEngine; using System.Collections;public class fireAndAnimation : MonoBehaviour {protected Animator animator;public GameObject target = null; public GameObject leftHand = null; public GameObject rightHand = null; public GameObject bazoo = null; public GameObject bullet = null; public GameObject FirePosition = null;private bool load = false;// Use this for initializationvoid Start () {animator = GetComponent<Animator>();}// Update is called once per framevoid Update () {if (animator){float aim = animator.GetFloat("Aim");float fire = animator.GetFloat("Fire");// 瞄准逻辑 if (Input.GetButton("Fire2")){if(!load && ( aim<0.)){load = true;} else if (load && aim >0. ){load = false;}} animator.SetFloat("Aim",load?1:0,0.1f,Time.deltaTime);//射击逻辑if(Input.GetButton("Fire1")&&fire<0.f&&aim>0.f){animator.SetFloat("Fire",1);if(bullet!=null&&FirePosition!=null){GameObject newBullet = Instantiate(bullet,FirePosition.transform.position,Quaternion.Euler(0,0,0)) as GameObject; Rigidbody rb = newBullet.GetComponent<Rigidbody>();if(rb!=null){ rb.velocity = FirePosition.transform.TransformDirection(Vector3.forward*);}} }else{animator.SetFloat("Fire",0,0.1f,Time.deltaTime);}float h = Input.GetAxis("Horizontal");float v = Input.GetAxis("Vertical");animator.SetFloat("Speed", h*h&#;v*v); animator.SetFloat("Direction", h, 0.f, Time.deltaTime);}} void OnAnimatorIK(int layerIndex){float aim = animator.GetFloat("Aim");if(layerIndex == 0){if(target!=null){Vector3 tPosition = target.transform.position;tPosition.y = tPosition.y &#; 0.2f*(tPosition- animator.rootPosition).magnitude;animator.SetLookAtPosition(tPosition);animator.SetLookAtWeight(aim,0.5f,.5f,0.0f,0.5f);if (bazoo != null) { float fire = animator.GetFloat("Fire"); Vector3 pos = new Vector3(-0.f, -0.f, -0.f); Vector3 scale = new Vector3(0.2f, 0.f, 0.2f); pos.x -= fire * 0.2f; scale = scale * aim; bazoo.transform.localScale = scale; bazoo.transform.localPosition = pos; } }}if (layerIndex == 1 ){if(leftHand!=null){animator.SetIKPosition(AvatarIKGoal.LeftHand,leftHand.transform.position);animator.SetIKPositionWeight(AvatarIKGoal.LeftHand,aim);}if(rightHand!=null){animator.SetIKPosition(AvatarIKGoal.RightHand,rightHand.transform.position);animator.SetIKPositionWeight(AvatarIKGoal.RightHand,aim);}} }}

推荐整理分享Unity3D 里IK手柄的用运(unity手柄圆盘),希望有所帮助,仅作参考,欢迎阅读内容。

Unity3D 里IK手柄的用运(unity手柄圆盘)

文章相关热门搜索词:unity 手柄插件,unity3d手机端摇杆,unity手柄控制,unity xbox手柄,unity3d手机端摇杆,unity手柄控制,unity手柄圆盘,unity手柄圆盘,内容如对您有帮助,希望把文章链接给更多的朋友!

Unity Shader 常用函数列表 CG标准函数库和C的标准函数库类,Cg提供了一系列内建的标准函数。这些函数用于执行数学上的通用计算或通用算法(纹理映射等),例如,需要求取入

System.Diagnostics.Process.Start操作文件和文件夹(Unity3D) 最近在学习U3D,会写一些脚本工具,操作文件。比如在unity中打开文本:varlogPath=Application.persistentDataPath/log;varfileName=newDirectoryInfo(logPath).GetFiles().OrderBy(t=

[置顶] unity3d Human skin real time rendering 真实模拟人皮实时渲染 先放出结果图片。。。由于网上下的模型是拼的,所以皮,脸颊,嘴唇看起来像存在裂痕,解决方式是加入曲面细分和置换贴图进行一定隆起,但是博

标签: unity手柄圆盘

本文链接地址:https://www.jiuchutong.com/biancheng/384517.html 转载请保留说明!

上一篇:Unity3D选择性渲染技术(unity 3渲2)

下一篇:Unity Shader 常用函数列表(unity shader saturate)

  • 什么是税务学
  • 所得税费用会计准则
  • 财务软件交多少钱印花税
  • 现金销售收入是净收入吗
  • 领取营业执照后30天内没做税务登记
  • 小规模纳税人年应税销售额标准是
  • 进项税额抵扣一般多少
  • 产权转让与股权转让
  • 跨年度借款利息的税务处理怎么做?
  • 2020年减免水利基金会计分录
  • 暂估的成本跨年了怎么冲销后要调整报表吗
  • 免租期租金能否确认递延所得税吗?
  • 会计人员必备的知识和技能
  • 境外单位或者个人
  • 固定资产报废处置账务处理
  • 外包人员培训费入什么科目
  • 库存周转天数计算实例
  • 个人独资企业简易注销流程及材料
  • win7电脑怎么开
  • macos big sur如何
  • 医生规培生补贴每年多少钱
  • 撤销权之诉需要哪些证据
  • 已经提完折旧的设备改造
  • PHP:oci_statement_type()的用法_Oracle函数
  • php 钩子
  • PHP:Memcached::getServerByKey()的用法_Memcached类
  • linux怎么打开makefile
  • php 正则表达式
  • 员工内部罚款有没有上限和下限
  • 所有者权益期末减期初等于净利润还是利润总额
  • 变动成本产品成本包括哪些
  • 银行提取现金会查征信吗
  • php获取get请求数据
  • php面向对象编程实验总结
  • 员工报销的差旅费属于什么科目
  • 模拟电子技术基础知识点总结
  • 腾讯云验证码服务
  • 应收账款科目怎么看
  • iozone测试结果分析
  • 企业注销时应收账款需要交税吗
  • 公司名义送花圈
  • 企业所得税季初和季末怎么算
  • 发票红字冲回账务处理
  • 视同销售是填在申报表的哪一栏?
  • 获取sqlsession
  • 代数分配法的优缺点和适用范围
  • 用友软件数据导出
  • 管理人员工资结构
  • 产品检测费计入什么二级科目里
  • 计提坏账准备不属于企业的或有事项
  • 人力资源公司的盈利模式
  • 农产品没有发票怎么办
  • 公司怎么才算正常经营
  • 个体工商户个税2023最新政策
  • 账户记录试算不平衡说明记账肯定有差错对吗
  • sql取两个时间的间隔天数
  • mysql批量更新多条数据
  • windos基于
  • 设置centos时区修改时间的方法
  • linux查看磁盘挂载的命令
  • 远程桌面连接xp系统
  • win7 32位无线网卡驱动
  • c#+unity3d
  • web ui控件
  • 如何让卖家给你乖乖退款
  • cocos2dx4.0教程
  • jQuery插件能输出到控制台
  • Node.js中的什么模块是用于处理文件和目录的
  • node发送邮箱
  • 每天自动重启命令
  • python list set dict tuple
  • js验证正整数
  • Python连接MySQL并使用fetchall()方法过滤特殊字符
  • 城市配套费需要什么资料
  • 收到红字信息表不能直接开具
  • 国家税务局申报系统操作步骤说明在哪里看
  • 环保税征税范围噪音
  • ca证书登录不了网厅怎么办
  • 亮点纷呈的意思和造句
  • 政务公开事项目录编制
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设