How can I fix enemy AI state machine transitions between patrol and chase?
#1
I’ve been trying to implement a proper state machine for my enemy AI, but I keep running into messy transitions where the enemy gets stuck between patrol and chase. How do you cleanly handle the logic for an AI that needs to react to the player but also return to its routine? My current setup feels like a tangled web of conditionals.
Reply
#2
I had that ping-pong too. The fix that finally helped was a tiny patrol cooldown after the target disappears and a short grace period before re-entering chase. It keeps the agent from snapping back and forth every tick.
Reply
#3
I switched to a compact three state setup: patrol, chase, and investigate, with a simple priority check each update. It cut the tangled conditionals down a lot, but if the player blinks in and out of LOS the thing still wiggles a bit.
Reply
#4
Are you sure the real problem isn't perception latency or pathing? sometimes the NPC never actually reaches the player and so it stalls in chase, which feels like a stall even though the state machine is fine.
Reply
#5
One time I found myself chasing the idea of perfect transitions while the patrol path itself was randomizing too aggressively; I slowed patrol pacing and forced a deterministic waypoint step between transitions, but it felt less natural.
Reply


[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Forum Jump: