게임에서는 캐릭터의 손이나 발이 특정 지점에 특정 순간에 닿는 방식으로 움직여야 하는 상황이 종종 발생합니다. 예를 들어 캐릭터가 징검다리를 뛰어 건너가는 경우 또는 공중에 있는 가로 기둥을 점프해서 붙잡아야 하는 경우 등이 있습니다.
이러한 상황을 처리하기 위해 Animator.MatchTarget 함수를 사용할 수 있습니다.예를 들어 캐릭터가 단상 위로 점프하는 상황을 만들려 하고, 이 때 사용할 점프 업 이라는 애니메이션 클립이 준비되어 있다고 합시다.우선 캐릭터가 땅에서 떨어지기 시작하는 순간에 애니메이션 클립의 어느 지점에 있는지를 찾아야 합니다. 이 경우 정규화된 시간 기준으로 애니메이션 클립의 14.1% 또는 0.141 지점입니다.
또한 캐릭터가 두 발로 막 착지하는 순간이 애니메이션 클립에서 어느 지점인지도 찾아야 하는데, 여기서는 78.0% 또는 0.78 지점입니다.
이 정보를 사용하여 MatchTarget을 호출하는 스크립트를 생성하여 모델에 연결할 수 있습니다.
using UnityEngine;
using System;
[RequireComponent(typeof(Animator))]
public class TargetCtrl :MonoBehaviour {
protected Animator animator;
//the platform object in the scene
public Transform jumpTarget = null;
void Start () {
animator = GetComponent<Animator>();
}
void Update () {
if(animator) {
if(Input.GetButton("Fire1"))
animator.MatchTarget(jumpTarget.position, jumpTarget.rotation, AvatarTarget.LeftFoot,
new MatchTargetWeightMask(Vector3.one, 1f), 0.141f, 0.78f);
}
}
}
이 스크립트는 캐릭터를 움직여서 캐릭터가 현재 포지션에서 점프하여 목적지에 왼발로 착지하게 만들 것입니다. 명심할 점은 MatchTarget은 게임플레이 도중 적절한 시점에 호출되었을 때에만 보통 그럴싸한 결과가 나올 것이라는 점입니다.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.