08 November, 2010

Little City Mega Update: Part 1, Police bots

This post concerns the police bot AI in Little City. The creation process was helped tremendously by LucidChart and the UDN tutorial chapter on state programming.

I previously talked about the police bots that regulate player movement in Little City. Brief recap: the city is long abandoned, but the automated police still enforce the law. Until the player retrieves the appropriate item, they must still follow pedestrian traffic laws.

Pictured below is a condensed flowchart of the basic bot state machine. It doesn’t contain every single action contained in the code, but describes how the bot behaves.

(AI state flowchart - Click image to enlarge)


In simple English:
  1. The bot remains idle until given a target* (a foolhardy jaywalker.)
  2. Upon target receipt the bot goes to yellow alers. It waits (to give the player a chance to get back on the sidewalk if they stepped off by accident) then checks to see if the target has been unassigned.
  3. If the target is still assigned, the bot goes to red alert. It first confirms the target is good, and that there is a clear line of sight to the target. If the target is bad (either killed or the data is garbage,) it is unassigned and shooting is disabled.
  4. If the target is all good, the bot acquires a shot vector and fires until the target dies or escapes.
  5. If the target manages to hide, the bot stops shooting and a stand down timer starts. The timer will clear and the bot will immediately resume firing if the target re-appears.
  6. If the timer goes off, the bot stops shooting and goes back to yellow alert. A hiding player can safely emerge onto legal ground (a sidewalk or crosswalk with a walk signal.) If the player stays legal, the bot goes idle. If not, the bot returns to red alert.

*Target acquisition is done with trigger volumes surrounding forbidden areas. Stepping in the volume assigns the player as the new target for the bot. Stepping out of the volume unassigns the target. Trigger volume setups can be easily and quickly re-configured in Kismet, while confining the state machine and “tick” (or “frame” or “game loop”) functions to UnrealScript code.

Here’s a video of the bot in action (currently lacking a mesh and appropriate audio:)



The next Little City post will cover updates made to the 2D map, followed by greyboxing. Stay tuned!

No comments:

Post a Comment

Feel free to comment. I'd love to hear from you, whether you are a player or creator of games!