I have a navmesh agent I’m trying to move off another gameobject below it. I’m trying to move it forward in whichever direction it is looking by telling the agent to move in front of where the eyes are looking. This code moves the agent in a direction but not where it is looking. How can I make the agent move the direction the eyes of the agent are looking? Thanks
public float distance = 10f;
void OnTriggerStay(Collider c)
{
c.GetComponent<StateController> ().agent.destination = c.transform.position + c.GetComponent<StateController> ().eyes.forward * distance;
}
NavMeshAgent are especially usefull when you make a RTS-like game. Setting the destination of your units allow them to use the built-in path finding algorithme.
Using it this way seems strange for me but here is the solution :
In fact you say to your NavMeshAgent to move forward, corresponding to Vector3(0, 0, 1). You need to specify the distance or the movement will be almost invisible.
Edit : Nevermind, i’ve not seen the “OnTriggerStay”, well if you need to move forward OnTriggerStay it make sens… just use this :