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是相對於當前動畫的匹配開始,結束時間。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM