Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Root motion handle rotation

Discussion in 'Navigation' started by h0nka, May 1, 2015.

  1. h0nka

    h0nka

    Joined:
    Apr 7, 2013
    Posts:
    99
    Hey guys,

    I'm currently working on navigation fully controlled by root motion (animation-driven locomotion) for a project, and I have managed to set the velocity of the agent to be the root motion, but how do I enable root motion animation to control the rotation of the agent?

    Thanks!

    This is what i have so far:

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class MoveToTarget : MonoBehaviour {
    6.  
    7.     private NavMeshAgent agent;
    8.     private Animator anim;
    9.  
    10.     void Start () {
    11.  
    12.         agent = GetComponent<NavMeshAgent>();
    13.         anim = GetComponent<Animator> ();
    14.  
    15.         anim.applyRootMotion = true;
    16.         agent.updatePosition = true;
    17.         agent.updateRotation = true;
    18.     }
    19.    
    20.     // Update is called once per frame
    21.     void Update () {
    22.  
    23.         if(GameObject.Find("Pickup(Clone)") != null)
    24.             agent.destination = GameObject.Find("Pickup(Clone)").transform.position;
    25.     }
    26.  
    27.     void OnAnimatorMove () {
    28.  
    29.         agent.velocity = anim.deltaPosition / Time.deltaTime;
    30.     }
    31. }
    32.  
     
  2. AShim-3D

    AShim-3D

    Joined:
    Jul 13, 2012
    Posts:
    32
  3. h0nka

    h0nka

    Joined:
    Apr 7, 2013
    Posts:
    99
  4. AShim-3D

    AShim-3D

    Joined:
    Jul 13, 2012
    Posts:
    32
    h0nka likes this.
  5. h0nka

    h0nka

    Joined:
    Apr 7, 2013
    Posts:
    99
    Late reply, sorry. Thanks a lot man!