- Home /
Looking forward while walking with navMeshAgent
Hello everyone ^^ I have a pretty "complicated" map as you can see in the picture on the bottom, whenever I want to instantiate a unit, I have to select a tower A where the units going our from, and a tower B where the units should go, the problem is I couldn't find a way to make the units always look forward and rotate whenever needed, is simple cases like in direct paths, it's easy, I just use look at, but for example if I try to move a unit from a blue house to the one in the center right, lookAt won't be what I need, what I am asking for now is a way to make the unit always look forward and rotate on curves, if anyone have already tackled such a thing, let me know ^^
Answer by hectorux · Nov 13, 2018 at 09:46 PM
You can get the navmesh velocity vector, if you get it, you can put that vector as the forward vector of your object
Thansk for your answer. Sadly it didn't work, the units just look forward I instantiate them in the blue tower, and they look towards the red ones :/ I used this transform.LookAt(agent.velocity);
@hectorux
you dont have to use the lookAt, what you have to do is to transform your vector3 to quaternion and set your rotation=your new quaternion
@hectorux I tried this but still won't work... transform.localEulerAngles = agent.velocity;