Unity3d 状态机行为可以';t修改对象';在对象具有根节点时进行s变换

Unity3d 状态机行为可以';t修改对象';在对象具有根节点时进行s变换,unity3d,Unity3d,学法语 我想在StateMachineBehaviour中控制我的旋转,并使用根运动动画移动对象 但当我的对象使用根节点进行根运动时,我不能在脚本中旋转它 我是如何做到这一点的: public class TestWalking : TestStateBase { // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state overri

学法语

我想在
StateMachineBehaviour
中控制我的
旋转
,并使用根运动动画移动对象

但当我的对象使用根节点进行根运动时,我不能在脚本中旋转它

我是如何做到这一点的:

public class TestWalking : TestStateBase
{
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {

    }

    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        MovingController movingController = GetMovingController(animator);

        if (Input.GetKey(movingController.inputManager.DicKeys[InputKeyType.KEY_MOVE_UP]))
        {
            movingController.vertical = 1;
        }
        else if (Input.GetKey(movingController.inputManager.DicKeys[InputKeyType.KEY_MOVE_DOWN]))
        {
            movingController.vertical = -1;
        }
        else
        {
            movingController.vertical = 0;
        }

        //Horizontal
        if (Input.GetKey(movingController.inputManager.DicKeys[InputKeyType.KEY_MOVE_LEFT]))
        {
            movingController.horizontal = -1;
        }
        else if (Input.GetKey(movingController.inputManager.DicKeys[InputKeyType.KEY_MOVE_RIGHT]))
        {
            movingController.horizontal = 1;
        }
        else
        {
            movingController.horizontal = 0;
        }

        if (movingController.horizontal != 0 || movingController.vertical != 0)
        {
            CalculateCamera(movingController);
            Rotate(movingController);
        }
    }

    // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
    override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        animator.SetBool("Walk", false);
    }


    void CalculateCamera(MovingController movingController)
    {
        movingController.camForward = movingController.camera.transform.forward;
        movingController.camRight = movingController.camera.transform.right;

        movingController.camForward.y = 0;
        movingController.camRight.y = 0;

        movingController.camForward = movingController.camForward.normalized;
        movingController.camRight = movingController.camRight.normalized;
    }

    void Rotate(MovingController movingController)
    {
        movingController.motion = (movingController.camForward * movingController.vertical + movingController.camRight * movingController.horizontal);
        if (movingController.motion.sqrMagnitude > 1)
        {
            movingController.motion.Normalize();
        }
        movingController.transform.rotation = Quaternion.Slerp(movingController.transform.rotation, Quaternion.LookRotation(movingController.motion), movingController.rotationSpeed);
    }
}
当对象有根节点时,不会发生任何事情。 当我从对象中删除根节点时,一切正常

我怎么能修好它?我仍然希望在状态机架构中使用根运动