其他分享
首页 > 其他分享> > Unity 根据前后帧位置自动旋转

Unity 根据前后帧位置自动旋转

作者:互联网

写在Update里面

     var newPos = transform.position;
        if (lastPos != newPos) {
            targetRotation = Quaternion.LookRotation(newPos - lastPos);
        }

        if (Math.Abs(transform.rotation.eulerAngles.y - targetRotation.eulerAngles.y) > 0.01f) {
            transform.rotation = Quaternion.Slerp(transform.rotation,
                Quaternion.Euler(new Vector3(0, targetRotation.eulerAngles.y, 0)), rotateSpeed);
        }

        lastPos = newPos;

 

标签:eulerAngles,targetRotation,lastPos,newPos,Quaternion,transform,旋转,Unity,自动
来源: https://www.cnblogs.com/sanyejun/p/14846589.html