Which movement type for AI controlled characters?

Imp079

New member
I am attempting to use the UCC for AI controlled, humanoid enemies in a 3D RPG, but I notice though that the animator controller's Yaw parameter stays at zero when using either the NavMeshAgentMovement ability or RotateTowards ability. We are using root motion for both position and rotation. I've tried combat, adventure, and RPG movement types but don't see much of a difference. What is the typical movement type for this? Or is a custom movement type necessary?

The desired behavior is that the enemies begin pathing towards the player once the player comes within aggro range (via the Nav Mesh Agent Movement ability). They stop pathing once they're within attack range, instead turning to face the player (via the RotateTowards ability). The enemies have animations for forward movement, turning, moving forward while turning, and, in some cases, strafing, so ideally they should use a combination of forward movement and strafing to move towards the player, while rotating to face the player (the strafing should zero out once they're facing the player). Looking at the animator controller, Behavior Designer behavior tree, and Ultimate Character Locomotion component during gameplay, everything seems to be in order except that the Yaw parameter remains at 0, so the turn animations never get triggered.

I also recently noticed that the ILookSource component is listed as a requirement for AI controlled characters. What does this component do in this context? We already have a component that produces headtracking, and it seems to be working.

Thanks!
 
The Yaw is set by the camera, and as the AI characters have no camera attached, it is always 0. The camera controller implements the ILookSource. For AI characters you have to assign the LocalLookSource instead of the camera.
 
Looking at the code for the LocalLookSource component, the relevant part of the interface seems to be the LookDirection function, which returns the character's forward vector if there is no current target, and the offset between the look position and the target if there is. I attached the LocalLookSource and it didn't seem make any difference, however I did not assign a look target. I would think though that if I did, and the vector returned by the LookDirection function is used to calculate the Yaw animator controller parameter, that the character would instantly rotate to face the look target, which would look bad for large rotations. Also, the LocalLookSource does not provide a way for the character to face the direction they are moving while pathing towards the player, other than by creating a dummy look target and placing it in the direction that they should be facing.

I did a "find all references" to see which scripts use the LookDirection functions, and the only relevant result seemed to be the first person combat movement type. Is that the appropriate movement type for AI controlled characters?

Will I need to write my own component that implements ILookSource, or do I need to calculate and assign Yaw some other way?
 
The LocalLookSource does not set the yaw value so I do recommend writing your own ILookSource for that situation. It should be a pretty small component.
 
What is the preferred way to set the Yaw on the animator monitor without it being overridden? It looks like AnimatorMonitor's SetYawParameter function is called by the UltimateCharacterLocomotion's UpdateAnimator function, which is in turn called by CharacterLocomotion's Move function. So Yaw is being set to m_YawAngle * m_YawMultiplier every frame. The m_YawAngle variable is protected, and its YawAngle accessor is read-only. I see that m_YawAngle is calculated from CharacterLocomotion's Torque, which has a setter. Can I just set Torque directly?
 
I just looked and the yaw angle is calculated from the character's rotation. So any ILookSource should work. The LookDirection method of the ILookSource will tell the character which direction they should look, and MovementType.GetDeltaYawRotation will tell the character which direction to turn. Maybe you want to create a new movement type for your situation?
 
I turned off root motion based rotation and it seems to have fixed the problem, using the LocalLookSource and Third Person Combat movement type. I think the problem is in how the Yaw parameter is calculated when rotational root motion is selected, but it's a complex chain of code that I haven't fully wrapped my head around yet. We'd ultimately prefer to keep root motion to make skating easier to avoid, but for now this gets the project working again.
 
Top