NavmeshAgent destination facing

Hi.

I want to use navmeshAgent and it’s steering capabilities. But I want to extend it, find a plug in, or perhaps find a way to do what I want to do using what’s available.

I’ll keep this simple. Suppose I have 2 points I want the agent to get to, for this example say I want to walk him to a door, wait for door to open, then walk through door to a location in the next room… It’s simple enough to set destination to first point, then when get there - wait - then set the destination to the next room.

However, what I want to do is set the first point so that he walks around using the agent’s steering system, and ends up facing the door.

Currently, depending on where he was previously in the room, he could end up facing with back to door, sideways, or whatever.

Now yes I could just rotate him when he gets there, using a slerp or similar, but that looks ugly. And of course I can control the rotation myself, but that’s also looks ugly.

Take the attached image. In image A, I want to start at the Green, end at the red facing the door (blue). Imagine there are obstacles in the way (not pictured)

If I use the navmeshAgent as it is, sometimes B happens, which ends with the agent facing sideways to the door (so now I have to rotate it - which looks stupid). Whereas C would’ve been better and more “realistic” as he ends up facing the door.

Now, second example. I start off in green facing right. and I want to end up where the red dot is facing the door.

Currently the navmeshagent will do E and i’ll end up facing away from the door (so now i’ll have to get there, and then rotate to the correct angle). What I’d like the nav mesh agent to do is to use it’s angular velocity and project a bit further into the future past the end point, so that it ends up facing the correct direction using the navmesh.

And indeed sometimes (due to the turning circle) I end up with the agent rotating past where he should end up facing, close to the end point. And then gets to the end point - and I have to rotate him back (Which again looks a bit daft)

Is this possible?

Or do I have to write my own navigation solutions?

Put your model in a child transform of the navmesh agent. Let the agent turn however it desires and turn the internal
Object to have it look where you want.

Thanks, that works in theory, but would end up with the agent looking in one direction while moving in another. I’d like something where the movement is tied to the direction you want to end up in.

Otherwise you end up with people moving along a wall while facing it, etc etc. But you dont always want to just get near destination then face it (Which also looks stupid), etc etc.

There must be a better way? It doesnt even seem like i can write my own navmeshagent as i dont have easy access to the data? Has anyone done anything like this?

I came across the same thing. I broke down the behavior into the chunks that I actually wanted. The enemy would either be watching where it was going or looking at its target. I have a Boolean that can be swapped on the fly to let it look in the direction of the nav agent or at the enemy. It’ll look at the player only if it’s within a certain distance and actually has line of sight to the target. In all other cases it just turns with the nav agent.

Hi, I’ve got something similar to what you describe but the turning motion when multiple enemies try to path around one another becomes very rapid and jerky - they sort of flick between directions very quickly. Did you ever experience this problem?

The logic behind the tools is very limited. Maybe you could extend it adding an lets say sphere collider as trigger and if hits another navmeshagent take some evasive action to avoid cluttering.

About the agent facing. The agent don’t know intentions so, can not infer you want it to face the door so that is something that need to be coded by yourself.
Something I found allow me a more natural behavior is disable the agent control on the rotation and keep it updated manually based on the steering.

I believe the NavMeshAgent lets you turn on / off whether or not it faces towards it’s movement vector. I’m not sure if you use something like a StateMachine, but it’s easier to approach as an animation issue instead of a navigation issue. You could opt to set up a more complex animator and blend in some turning or play with animation rigging whenever manual turning happens.

You could also set up an approach point for your door and then a contact point slightly closer to it. Have your agent navigate to the approach point first, then let it move towards the actual contact point. Tadaa: your dude now approaches from the angle you want for your animation to look natural.

1 Like