Making a UCC agent aim at a target while moving around it using NavMesh/Astar

Cheo

Active member
Hello, this is something @Grannyboy and I have been struggling with recently, basically we're both trying to make a UCC agent character constantly aim at a target while moving around it using pathfinding, whether it be Unity's Nav Mesh or Astar. Here is as usual a video about it :


I gave the Deathmatch AI Kit demo scene another quick try and saw enemy agents able to keep facing the player while staying still, but couldn't very well see them doing so while moving around him. So are we missing something here, or is there an actual issue with the way aiming and pathfinding are handled ? Thanks in advance.
 
There are multiple systems at play and depends on your situation. For AI agents you should use the combat movement type which will allow the character to strafe or move backwards. Aiming is a separate system and for that you can override the rotation with the aim ability. Then on the pathfinding ability you can prevent it from managing the rotation.
 
Alright, I think I got it ! In UpdateRotation in the Aim script, there is an if statement that checks for all of this :

C#:
            if (m_LookSource == null || !m_RotateTowardsLookSourceTarget || (m_AssistAim != null && m_AssistAim.IsActive && m_AssistAim.RotateCharacterTowardsTarget) ||
                (m_PathfindingMovement != null && m_PathfindingMovement.IsActive))

If we remove the last part about pathfinding, set the override to Character on the Nav Mesh Agent Movement ability or set Enable Rotation to false on AI Path, and set Rotate Towards Look Source to true on Aim, then the character can perform both the patrol movement and the aiming rotation correctly !
 
Top