NavMesh and Animation

³×ºñ¸Þ½¬ÀÇ ¼Óµµ¿¡ µû¶ó ij¸¯ÅÍÀÇ ¾Ö´Ï¸ÞÀ̼ÇÀ» Á¦¾î Çغ¸ÀÚ.
ÀÚ¼¼ÇÏ°Ô À̾߱â ÇÏÀÚ¸é NavMeshAgent.velocity.sqrMagnitude °ªÀ¸·Î ¾Ö´Ï¸ÞÀÌ¼Ç »óŸ¦ Á¦¾î ÇÒ°ÍÀÌ´Ù.

ÇϳªÀÇ °ªÀ¸·Î ¾Ö´Ï¸ÞÀ̼ÇÀ» Á¦¾îÇϱâ À§ÇØ BlendTree¸¦ »ç¿ëÇÑ´Ù.

»ç¿ëÇÑ Ä³¸¯ÅÍ ¸®¼Ò½º´Â "Unity Chan" ij¸¯ÅÍÀÌ´Ù.



1. "Animator Controller"¸¦ ¸¸µç´Ù.



2. ¸Þ´º > Window > Animator â ¿­±â

3. Animator-Parmeters¿¡ MoveSpeed( float )¸¦ Ãß°¡ÇÑ´Ù.



4. Animatorâ¿¡¼­ "From New Blend Tree"·Î ºí·»µå Æ®¸®¸¦ ¸¸µç´Ù.



5. Blend Tree¸¦ ´õºí Ŭ¸¯ÇÏ¿© ºí·£µå Æ®¸® â ¿­±â





6. "Add Motion"À¸·Î ¸ð¼ÇÀ» Ãß°¡ÇÑ´Ù.
idle, walk, run 3°¡Áö µ¿ÀÛÀ» Ãß°¡ÇÑ´Ù.



¶Ç´Â



¸ð¼ÇÀ» Ãß°¡ÇÏ¸é ´ÙÀ½°ú °°Àº »óÅ°¡ µÈ´Ù.



¶Ç´Â



7. Animation ClipÀ» Motion¿¡ µå·¡±× ÇÑ´Ù.



8. ÀÓ°è°ª(Threshold)À» ¼³Á¤ÇÑ´Ù.
Idle = 0
walk = 0.3
run = 5



9. BlendTree¿¡¼­ ÆĶó¸ÞÅÍ°¡ "MoveSpeed"ÀÎÁö È®ÀÎ ÇÑ´Ù.
BlendTree¿¡¼­ Blend TypeÀÌ "1D"À̸é Parameter º¯¼ö(¿©±â¼­´Â MoveSpeed) Threshold(ÀÓ°è°ª)¿¡ ÀÇÇØ MotionÀÌ °áÁ¤µÈ´Ù.

Áï, MoveSpeed°¡ 0À̸é idle, 0.3º¸´Ù ÀÛÀ¸¸é walke, 0.3º¸´Ù Å©¸é run µ¿ÀÛÀ» ÇÑ´Ù.




10. ´ÙÀ½°ú °°Àº ÆÄÀÏÀ» ¸¸µé°í ¾Ö´Ï¸ÞÀÌ¼Ç ÇÒ Ä³¸¯ÅÍÀÇ ÄÄÆ÷³ÍÆ®·Î Ãß°¡ÇÑ´Ù.
¾îµð·Î ¿òÁ÷ÀÏÁö ¸ñÇ¥ Ÿ°ÙÀÎ TargetÀ» ¼³Á¤ÇÑ´Ù.

³×ºñ¸Þ½¬ ¼Óµµ agent.velocity.sqrMagnitude·Î ¾Ö´Ï¸ÞÀ̼ÇÀ» Á¦¾îÇÑ´Ù.
¾Ö´Ï¸ÞÀÌ¼Ç Á¦¾î´Â "MoveSpeed"·Î ÇÑ´Ù.

animator.SetFloat("MoveSpeed", agent.velocity.sqrMagnitude)

NavNpcMove.cs ÆÄÀÏ
using UnityEngine;

[RequireComponent(typeof(NavMeshAgent), typeof(Animator))]
public class NavNpcMove : MonoBehaviour
{
    [SerializeField, HideInInspector]
    NavMeshAgent agent;
    [SerializeField, HideInInspector]
    Animator animator;

    public GameObject Target;

    void Start()
    {
        Debug.Log("<<< Start");
        GetComponent<NavMeshAgent>().SetDestination(Target.transform.position);
    }

    void Reset()
    {
        Debug.Log("<<< Reset");
        agent = GetComponent<NavMeshAgent>();
        animator = GetComponent<Animator>();
    }


    void Update()
    {
        Debug.Log("MoveSpeed: " + agent.velocity.sqrMagnitude);
        animator.SetFloat("MoveSpeed", agent.velocity.sqrMagnitude);
    }
}

RequireComponent·Î NavMeshAgent ÄÄÆ÷³ÍÆ®¸¦ Ãß°¡ÇÏ°í À¯´ÏƼ Reset ÇÔ¼ö¿¡¼­ agent, animator º¯¼ö¸¦ ¼³Á¤ÇÏ°í ÀÖ´Ù.
Reset ÇÔ¼ö´Â Awake, Enabe, Start º¸´Ùµµ ¸ÕÀú ½ÇÇàµÈ´Ù.

Âü°í)
¸ÞÀÎ ÂüÁ¶
http://tsubakit1.hateblo.jp/entry/2015/07/02/233000

Reset ÇÔ¼ö ¼³¸í
http://itmining.tistory.com/47