- Home /
NavMesh Agent rotation problem
I bought a character pack with animations. I am using NavMesh Agent components for path finding but when I set destination and play, agent turns backwards and start walking backwards (like Moonwalk). I used lots of different characters with NavMesh Agents before but this is the first time I am in this kind of trouble. I tried all kind of rotation options (with coding or manually) but didn't work.
In other words, is there a way to change NavMesh Agent face rotation?
I've also faced a problem with the direction of the navigation while applying the navmesh agent to a gameobject with mouse look script attached.
Please, help, I have the same problem. Is there any way to change through scripting or smth, 'cause I have no way to fix the fbx model myself.
Answer by laradov · Jul 04, 2013 at 03:02 PM
I am answering my own question :) This is how I solve it (I think it is not a good solution but it works) ; Create an empty game object ,add NavMesh Agent component (and scripts if you have) and put the model inside it in reverse angle(set the model position as (0,0,0) and rotation as (0,180,0) or the axis you use). In fact you are controlling the empty object but since the empty game object is invisible, it looks like you are controlling the model.
This solved the issue. To think I halted development for 4 months because. Is this a bug in navmeshAgent?
Answer by Tlasol · Jul 04, 2013 at 03:24 PM
There's another way :) Found it.
Depends on your model, but there is a way to transform rotation of Y to 180 degrees on one or another layers. Still there may be a problem with pivots, which causes offset from center of navmeshagent, but it's okay and easy to fix with 'position'.
Answer by Johnad194 · Jan 28, 2019 at 11:45 PM
A little late, but you could always export the model to blender or your choice of 3D modelling software and rotate it there. I personally prefer this method to having as many nested GameObjects in my hierarchy.
Answer by kami1339 · Apr 03, 2019 at 08:18 PM
SOLVED 1 Make an empty object 2 put your object in to your empty object 3 set all your rotation"s object to 0(zero) 4 rotate your object and test navigation!
Testing
A- choose your empty object and ad thsi companent to it companent>navigation>navigation mesh agent. B- add this script to your empty object.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;///////////////////important
public class playernavigation : MonoBehaviour {
public GameObject target;
public NavMeshAgent navMeshAgent;
void Start () {
navMeshAgent = GetComponent<NavMeshAgent> ();
}
// Update is called once per frame
void Update () {
//GameObject.Find("Cube").transform.position;
navMeshAgent.SetDestination (target.transform.position);
}
}
//navMeshAgent.SetDestination (new Vector3(x,y,z));
Your answer
Follow this Question
Related Questions
How to queue NavMeshAgents on entering a tile in Unity (based on path distance to tile)? 0 Answers
Making NavMesh areas? 0 Answers
NavMeshAgent collision not working with player 2 Answers
How to prevent NavMeshAgents from colliding when warped to same position? 0 Answers
Is it possible to store NavMeshAgents paths and assign them to other NavMeshAgents later? 1 Answer