unity 使对象不悬空

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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值