一開始會理所當然的覺得,匹配是這樣的:
但結果卻是這樣的(右邊的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(); } }
使用方式:
1.TargetMatching只能工作在base layer
2.InterruptMatchTarget中的completeMatch設為True的話,會立即結束插值自動跳到目標匹配位置。
3.MatchTargetWeightMask是和原有動畫之間的權重,如果為1就是完全控制。
4.isMatchingTarget字段確定當前是否在匹配狀態
5.startNormalizedTime和targetNormalizedTime是相對於當前動畫的匹配開始,結束時間。