动画目标匹配

public class L46 : MonoBehaviour
{
    public Animator ani;
    public Transform targetPos;
    // Start is called before the first frame update
    void Start()
    {
        ani = GetComponent<Animator>();
        //角色完成某个动作后,人物的手或脚必须落在一个地方,就需要动画目标匹配

        //实现动画目标匹配
        //1.找到动作关键点位置信息(比如起跳点,落地点,就是真正可能产生位移表现的动画部分)
        //2.将关键信息传入MatchTarget的API中

        //必须保证动画已经切换到目标动画上
        //必须保证调用时的动画不是处于过渡阶段而是真正在播放目标动画
        //需要开启Apply Root Motion
    }
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            ani.SetTrigger("Jump");

        }
    }
    //一般通过动画事件调用
    public void MatchTarget()
    {
        //(目标位置,目标角度,匹配的骨骼位置,位置角度权重(MatchTargetWeightMask),开始有位移表现时动画播放百分比,结束位移表现时动画播放的百分比)
        ani.MatchTarget(targetPos.position, targetPos.rotation, AvatarTarget.LeftFoot, new MatchTargetWeightMask(Vector3.one, 1), 0.4f, 0.64f);
    }
posted @ 2025-04-09 11:45  cannedmint  阅读(15)  评论(0)    收藏  举报