Unity-Animator深入系列---目标匹配Target Matching

回到 Animator深入系列总目录

 

 

一开始会理所当然的觉得,匹配是这样的:

 

但结果却是这样的(右边的Cube是匹配目标):

 

 

感觉这个接口应该是专门为攀爬之类的动画准备的,属于被动匹配位置,移动整个对象去匹配

所以像游戏中的斜面双脚的IK匹配,就和这个接口没关系了:

 

 

 

OK,下面附上测试代码:

using UnityEngine;

public class MatchTargetExample : MonoBehaviour
{
    public Animator animator;
    public GameObject testTarget;


    [ContextMenu("Start Match")]
    void StartMatch()
    {
        animator.MatchTarget(testTarget.transform.position, testTarget.transform.rotation, AvatarTarget.LeftHand, new MatchTargetWeightMask(Vector3.one, 1f), 0f);
    }

    [ContextMenu("Interrupt Match Target")]
    void InterruptMatchTarget()
    {
        animator.InterruptMatchTarget();
    }
}
MatchTargetExample

 

使用方式:

 

 

 

1.TargetMatching只能工作在base layer

2.InterruptMatchTarget中的completeMatch设为True的话,会立即结束插值自动跳到目标匹配位置。

3.MatchTargetWeightMask是和原有动画之间的权重,如果为1就是完全控制。

4.isMatchingTarget字段确定当前是否在匹配状态

5.startNormalizedTime和targetNormalizedTime是相对于当前动画的匹配开始,结束时间。

posted @ 2016-01-03 10:58  HONT  阅读(3789)  评论(0编辑  收藏  举报