社区
Unity3D
帖子详情
NavMashAgent和Animation
a839398
2017-12-04 07:45:35
我用Animation设置了角色动画的切换,键盘监听角色的移动,角色的移动、转向和动画切换都正常
然后我用NavMashAgent设置角色的自动寻路的时候,角色可以移动到目标地点。
但是自动寻路的过程中动画切换出了问题。角色有两个动作stand和run。如果没有障碍物角色一直站着移动到终点,如果有障碍物,角色就跑着绕过障碍物,之后又是站着到终点。
...全文
444
4
打赏
收藏
NavMashAgent和Animation
我用Animation设置了角色动画的切换,键盘监听角色的移动,角色的移动、转向和动画切换都正常 然后我用NavMashAgent设置角色的自动寻路的时候,角色可以移动到目标地点。 但是自动寻路的过程中动画切换出了问题。角色有两个动作stand和run。如果没有障碍物角色一直站着移动到终点,如果有障碍物,角色就跑着绕过障碍物,之后又是站着到终点。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
a839398
2017-12-07
打赏
举报
回复
谢谢你,这个问题困扰了我几天了。以为要很久才有回复,没想到这么快。我再写一下代码先。
ttod_qzstudio
2017-12-06
打赏
举报
回复
如果你判断一个角色是否正在移动,似乎没必要使用rigidbody,判断相邻两帧位置的距离(建议使用距离的平方,这样计算量小一点儿)是否接近0就可以了,rigidbody组件容易添加额外的干扰。 总的来说这个事情应该可以把逻辑写的简单些,我觉得你的意思好像是这样吧: 角色控制分两种,一种是通过键盘操作,一种是自动寻路,通过键盘上的某个键可以切换控制状态。 角色动作的播放和控制是没有关系的,只和移动速度有关,接近0就是站立,否则就是跑动。 你上面的代码有一点点复杂了,再缕一下思路吧。
a839398
2017-12-05
打赏
举报
回复
我昨天没在自己的电脑上的网,家里面没网络,就没有发代码
a839398
2017-12-05
打赏
举报
回复
using UnityEngine; using System.Collections; public class BoyAnimationVillage : MonoBehaviour { private Animator anim; void Start() { anim = transform.GetComponent<Animator>(); } // Update is called once per frame void Update () { if (transform.GetComponent<Rigidbody>().velocity.magnitude >0.1f)//判断刚体Rigidbody的速度是否大于0.01 { //transform.GetComponent<Rigidbody>().freezeRotation = false; anim.SetBool("Move", true);//设置动画切换 } else { anim.SetBool("Move", false);//设置动画切换 transform.GetComponent<Rigidbody>().freezeRotation = true; } } } //================================================================================== using UnityEngine; using System.Collections; public class PlayerVillageMove : MonoBehaviour { public float velocity = 5; private NavMeshAgent agent; void Start() { agent = this.GetComponent<NavMeshAgent>(); } void Update () { float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); Vector3 vel = rigidbody.velocity; if (Mathf.Abs(h) > 0.05f || Mathf.Abs(v) > 0.05f) { rigidbody.velocity = new Vector3(-h * velocity, vel.y, -v * velocity); transform.rotation = Quaternion.LookRotation(new Vector3(-h, 0, -v)); } else { if (agent.enabled == false) { rigidbody.velocity = Vector3.zero; } } if (agent.enabled) { transform.rotation = Quaternion.LookRotation ( agent.velocity ); } } } //========================================================================================= using UnityEngine; using System.Collections; public class PlayerAutoMove : MonoBehaviour { private NavMeshAgent agent; public float minDistance = 3; void Start () { agent = this.GetComponent<NavMeshAgent>(); } void Update () { if (agent.enabled) { if (agent.remainingDistance < minDistance &&agent.remainingDistance!=0 ) { agent.Stop(); agent.enabled = false; TaskManager._instance.OnArriveDestination(); } } float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); if (Mathf.Abs(h) > 0.05f || Mathf.Abs(v) > 0.05f) { StopAuto();//如果在寻路过程中 有按下移动控制键,那么就停止寻路 } } public void SetDestination( Vector3 targetPos ) { agent.enabled = true; agent.SetDestination(targetPos); } public void StopAuto() { if (agent.enabled) { agent.Stop(); agent.enabled = false; } } }
wpf
Ani
ma
tion
动画效果演示,包含多个实例
利用WPF
Ani
ma
tion
开发的动画,包含多个实例,附源码
Android 属性动画(Property
Ani
ma
tion
) 完全解析 源码程序
代码为博客实例代码:http://blog.csdn.net/lmj623565791/article/details/38067475 有问题博客留言
Flutter动画基础教程
本次课程包含以下内容: 动画基本概念 动画的本质 帧与FPS 插值器/估值器 动画类型 动画相关核心类
Ani
ma
tion
介绍
Ani
ma
tion
Controller动画管理类 Curved
Ani
ma
tion
非线性动画 Tween补间值生成类 动画事件监听及控制...
NineoldAndroids jar 包
Nineoldandroids包,由Github大牛jake wharton 开发,令Property
Ani
ma
tion
可以支持到1.x
unity
Ani
ma
tion
State和
ani
ma
tion
clip的区别
想知道unity
Ani
ma
tion
State和
ani
ma
tion
clip的区别,就要先了解unity
Ani
ma
tion
State和
ani
ma
tion
clip,下面我们先学习一下unity
Ani
ma
tion
State和
ani
ma
tion
clip,它们的区别就一目了然啦。
Ani
ma
tion
Clip ...
Unity3D
2,537
社区成员
2,141
社区内容
发帖
与我相关
我的任务
Unity3D
Unity3D相关内容讨论专区
复制链接
扫一扫
分享
社区描述
Unity3D相关内容讨论专区
游戏
unity
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
Unity3D社区公告:
社区致力于解决各种Unity3D相关的“疑难杂症”。
社区不允许发布与Unity3D或相关技术无关内容。
社区版主邀请各位一道为打造优秀社区不懈努力。
试试用AI创作助手写篇文章吧
+ 用AI写文章