Have NPC orient toward look target while navigating; fix nav agent startup race.#189
Open
zhuberty wants to merge 1 commit into
Open
Have NPC orient toward look target while navigating; fix nav agent startup race.#189zhuberty wants to merge 1 commit into
zhuberty wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes NPCs orient their body toward their look target while navigating, so they face what they're chasing rather than the path direction. Also disables the NavMeshAgent's built-in rotation so it no longer fights manual body rotation, and fixes a startup race condition that caused the nav agent to immediately report failure before it had a chance to begin navigating.
Motivation & Context
Previously, when an NPC was chasing a player (or any look target), the body would only rotate to face the target once the angle exceeded
MaxHeadAngle(45°). During navigation the NavMeshAgent was also overriding body rotation to match the path direction, causing the NPC to look sideways or away from the player while closing the gap. Additionally, animation blend parameters (move_x/move_y) were computed relative to the agent's path rotation rather than the body's actual facing direction.A secondary issue caused the scientist NPC to immediately drop props it had just picked up: the nav agent re-issue logic and the failure check ran in the same frame, so
GetStatus()saw!Agent.IsNavigatingbefore the agent had a chance to start and returnedFailed, ending the schedule prematurely.Fixes:
Implementation Details
Code/Npcs/Tasks/MoveTo.cs— Body rotation now branches on whether a look target is set. When one is present (e.g. chasing a player), the body rotates to face the look target directly each frame regardless of angle. When no look target is set, the existing lateral-threshold behavior is preserved to avoid sideways walking.code/Npcs/Layers/NavigationLayer.cs— Four changes:Agent.UpdateRotation = falseon start so the NavMeshAgent no longer overrides manual body rotation.SetMovenow passesNpc.WorldRotationinstead ofAgent.WorldRotationso animation blend parameters are computed relative to where the body is actually facing.OnUpdatethat re-callsAgent.MoveToif the navmesh finishes building while the agent isn't navigating (handles procedurally generated geometry)._timeSinceLastMoveIssuedgrace period (0.1s) inGetStatus()so the agent isn't immediately declared failed before it has had a chance to start navigating after a move is issued.Screenshots / Videos (if applicable)
sbox.2026.04.17.14.10.37.mp4
Checklist