Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Root motion handle rotation

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

  1. h0nka

    h0nka

    Joined:
    Apr 7, 2013
    Posts:
    109
    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:
    33
  3. h0nka

    h0nka

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

    AShim-3D

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

    h0nka

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