C# 通过动画正确使用更新和修复更新运动

C# 通过动画正确使用更新和修复更新运动,c#,unity3d,C#,Unity3d,我读了很多书,我有一些想法,但不是100%确定如何正确处理游戏对象的运动和动画。在这种情况下,这是我的球员移动脚本 所以我想知道的是,我应该把我的“运动”变量的逻辑放在我的更新或FixedUpdate中吗?我应该在我的动画位置处于更新或FixedUpdate中的情况下更改任何内容吗?我尝试了这两种方法,我看到了相似的结果,但我只想在大型项目出现时有良好的实践 void Update(){ // IF we are allowed to move. if(_PMS.canMove)

我读了很多书,我有一些想法,但不是100%确定如何正确处理游戏对象的运动和动画。在这种情况下,这是我的球员移动脚本

所以我想知道的是,我应该把我的“运动”变量的逻辑放在我的更新或FixedUpdate中吗?我应该在我的动画位置处于更新或FixedUpdate中的情况下更改任何内容吗?我尝试了这两种方法,我看到了相似的结果,但我只想在大型项目出现时有良好的实践

void Update(){
    // IF we are allowed to move.
    if(_PMS.canMove){
        // Get a -1, 0 or 1.
        moveHorizontal = Input.GetAxisRaw ("Horizontal");
        moveVertical = Input.GetAxisRaw ("Vertical");
        // Get Vector2 direction.
        movement = new Vector2(moveHorizontal * _PMS.invertXDirection, moveVertical * _PMS.invertYDirection);
        // Apply direction with speed.
        movement *= speed;
        // IF the user has an animation set.
        if(anim != null){
            // Play animations.
            Helper_Manager.PlayerAnimation(moveHorizontal, moveVertical, anim, _PMS);
        }
    }
}

void FixedUpdate(){
    // IF we are allowed to move.
    if(_PMS.canMove){
        // Apply the force for movement.
        rb.AddForce(movement);
    }
}

动画应与物理运动一起触发。我会将所有的移动计算移到FixedUpdate()中,然后只在Update()中获取输入。这样,所有的运动和动画一起触发

void Update() {

    // IF we are allowed to move.
    if(_PMS.canMove){
        // Get a -1, 0 or 1.
        moveHorizontal = Input.GetAxisRaw ("Horizontal");
        moveVertical = Input.GetAxisRaw ("Vertical");
    }
}

void FixedUpdate(){
    // IF we are allowed to move.
    if(_PMS.canMove){
        // Get Vector2 direction.
        movement = new Vector2(moveHorizontal * _PMS.invertXDirection, moveVertical * _PMS.invertYDirection);
        // Apply direction with speed.
        movement *= speed;
        // IF the user has an animation set.
        if(anim != null){
            // Play animations.
            Helper_Manager.PlayerAnimation(moveHorizontal, moveVertical, anim, _PMS); // always call this, assuming you play an idle animation if moveHorizontal and moveVertical are 0
        }

        // Apply the force for movement.
        rb.AddForce(movement);
    }
}