unity Animator做简单的人物动画

做一个简单的总结。人物动画的核心是状态机的设置,配合脚本的参量,来实现各组动画的转换。当然,我现在也只会最简单的动画。

状态机的设置有几个坑需要记一下:

  1. Apply Root Motion:在Animator中最好取消勾选,这个选项的意思是将动画的角度变换应用到场景中,但这样子会影响我们脚本的使用;
  2. 状态机设置添加Make Transition时,要把Has Exit Time取消勾选,不然的话一个动画没完它是不会放你想要的动画的。
  3. 参量设置需要脚本的配合,应用到animator.SetXXX("参量名", 脚本参量名)这个函数。

到现在,人物动画最常用的有两个参量:speedangle。下面是配合设置的脚本。

Vector3 velocity = (m_transform.position - last_position) / Time.deltaTime;
localVelocity = m_transform.InverseTransformDirection(velocity);
localVelocity.y = 0;
speed = localVelocity.magnitude;
//angle = (HorizontalAngle(localVelocity) + 360.0f) % 360.0f;

last_position = m_transform.position;
m_animator.SetFloat("Speed", speed);
//m_animator.SetFloat("Angle", angle);

//Debug.Log("speed: " + speed);
原文地址:https://www.cnblogs.com/ChanWunsam/p/10018313.html