回到 Animator深入系列總目錄
一開始會理所當然的覺得,比對是這樣的:
但結果卻是這樣的(右邊的Cube是比對目标):
感覺這個接口應該是專門為攀爬之類的動畫準備的,屬于被動比對位置,移動整個對象去比對
是以像遊戲中的斜面雙腳的IK比對,就和這個接口沒關系了:
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5CN1EDMyIDOyQTMtkDOwEzM5EjMxMDMxAjNxAjMtkDMwkTM18CXxAjNxAjMvwVOwATOxUzLcd2bsJ2Lc12bj5ycn9Gbi52YuUTMwIzcldWYtl2Lc9CX6MHc0RHaiojIsJye.png)
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是相對于目前動畫的比對開始,結束時間。