unity 使对象不悬空

来源:互联网 发布:淘宝宝贝优化 编辑:程序博客网 时间:2024/04/29 19:19

1.问题描述:当人物下楼梯时,使悬空的对象,落到地面上

解决方法:利用刚体的 Velocity  属性,注意,该语句应该写在FixedUpdate方法体内

void FixedUpdate () {        float h = ETCInput.GetAxis("Horizontal");        float v = ETCInput.GetAxis("Vertical");        animator.SetFloat("speed", h * h + v * v);        animator.SetFloat("run", h * h + v * v);           if (Mathf.Abs(h) > 0.05 || Mathf.Abs(v) > 0.05)        {            rig.velocity = new Vector3(h * moveSpeed, rig.velocity.y, v * moveSpeed);        }}



2.

Animator.applyRootMotion



Root motion is the effect where an object's entire mesh moves away from its starting point but that motion is created by the animation itself rather than by changing the Transform position.

当我们勾选此选项时,脚本中更改对象的  Transform  是没有作用的,Transform  的值是通过动画来改变的
当代码里含有 OnAnimatorMove() 方法时,可以进行一些相应的设置

0 0
原创粉丝点击