Unity uses animation's own

Check the "Apply Root Motion" that comes with Animator. "Apply Root Motion" will directly add the displacement to the object that mounts the Animator component. If the object does not collide with the capsule, the object will run out of the capsule . The situation shown in the figure below.

 Solution: Mount the script RootMotionControl on the level of Animator to monitor the displacement of Root Motion and pass it to ybot's father. 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RootMotionControl : MonoBehaviour
{

    Animator anim;
    private void Update()
    {
        anim = GetComponent<Animator>();
    }

    private void OnAnimatorMove()
    {
        SendMessageUpwards("OnUpdateRM", (object)anim.deltaPosition);
        //deltaPosition用来表示Root Motion的位移量
    }
}

 Code for RootMotionControl

The OnAnimatorMove function is called after the entire state machine is calculated. The state machine first calculates the final state, such as whether the final state is running, jumping or rolling halfway, and then calls RootMotionControl. If you are not satisfied with the final state, you can adjust it in this function.

//将OnAnimatorMove传递的参数在PlayerHandle中添加
public void OnUpdateRM(object _deltapos)
    {
        if (CheckState("attach1hC","attack"))//if条件是用来判断其它的,可以忽略
        {
            deltPos += (Vector3)_deltapos;
            //deltPos是用来储存传递过来的参数,累加一段时间后在FixedUpdate中统一加上
        }
    }
private void FixedUpdate()
    {
        rigid.position += deltPos;
    }

Guess you like

Origin blog.csdn.net/qq_62837200/article/details/129150922