- Home /
NavMeshAgent wait for rotation before moving
In Warcraft 3/Dota 2, the characters only begin to move after they have finished their rotation and are looking towards their next path position. How can I do this with the Unity's NavMeshAgent? I've tried stopping the agent ( nav.isStopped = true;
), then rotating it with Quaternion.Slerp
and resuming its movement again, but it doesn't work.
Answer by shadowpuppet · Jul 08, 2017 at 02:31 AM
raycast? i have scripts where my enemies do something if they rayhit something ( like if their gun is shooting at a wall they stop shooting) combine the lookat slerping thing with a raycast, when the character is facing next point he starts to move. The points would need the same tag. here are some snippets of what I mean
var rotation = Quaternion.LookRotation(Player.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);//damping is public float of how fast he rotates
thugRay = new Ray(transform.position + transform.up * draw- transform.right * off, transform.forward*dist);
Debug.DrawRay (transform.position+ transform.up * draw- transform.right * off, transform.forward*dist, Color.red);
if (Physics.Raycast(transform.position+ transform.up * draw- transform.right * off, transform.forward, out rayHit,dist)){
{
if(rayHit.transform.gameObject.tag == ("wall"))
{
agent.enabled = true;
agent.SetDestination(Player.transform.position);
///the transform up and right * draw and off are public floats to put the ray where I need it otherwise it draws it from their feet. so up = .7f in my case and the right (his gun barrel) is like .03f