Version 0.0.24 Released


This update continues to focus on the vehicle AI.  In this release I focused on the police AI.   The police AI is at the core of the game.  To simulate the thrill of the chase, we need to have police AI that have some intelligence about them while chasing the player (without cheating).  The major improvements that come in this release are 

  • Police slow down better when negotiating a turn either at an intersection while pursuing the player or at a dead-end T-intersection.
  • When there is a high density of obstacles like a traffic jam police slow down to better negotiate weaving around them.
  • Fixed a bug where the police would clock you when they could not even see you anymore, sorry!
  • Improved police search behavior when line of sight is lost and they are looking for you before giving up.

In the next update, I will revisit the traffic AI and continue making more improvements

  • Try and fix some of those pesky random movement bugs
  • Have traffic turning left yield to oncoming vehicles
  • Why the traffic suddenly loses its mind sometimes and starts ramming the car in front?

Technical Details:

For those a bit interested in the technical bits,

 I had designed the spline path following system for the Traffic AI and have found many uses of this data since.  The AI makes use of the behavior tree system built into Unreal Engine to divide responsibility and allow ticking at different rates for performance reasons.  Some code only needs to run every second. Other things run better 10 times a second. Currently nothing runs every frame as it is wasteful and unnecessary.


  With this data I can efficiently discover nearby obstacles and place them in better context than "20m" slightly in front of you.  While trying to completely phase out the old road segment system I had designed in the first version of the AI that uses the spline component data of the road splines in the landscape, I noticed that the police search behavior was still using it and had to put that system actor back in!  I quickly realized I could do a much better job of searching for the player if I used the road spline data that has more context around intersections and upcoming turns.  So I went to work on that and in the process also improved the intelligence of how the police try and find you after losing sight.  They first take an "investigate location" which is the last known location when one of the chasing police cars last sighted you.  Think of dispatch yelling "suspect last seen on Main St...".  It's also pertinent to note what direction the vehicle was traveling in at that location so dispatch can add "...traveling eastbound!"  At this point the police will try and move to that location.  If they don't see you at that point, they are wondering "hmmm, which way did they go?!?"  They then look ahead and if there is a cross roads, decide maybe we should try turning right here?  While writing this I realized, they probably should coordinate or attempt to "box" you in.  That is noted for a future milestone...  But with this change I was finally able to banish the old road system to oblivion. Out with the old and in with the new!

To slow down for obstacles, the police use the traffic spline positions that are posted to a global cache that is keyed by the vehicle pointer.  There is an initial high pass check that uses the Unreal perception data that is already gathered to note other vehicles that the police car car can currently "see".  You cannot dodge what you cannot see, right?  It's nice when existing systems build on each other and become a force multiplier for future enhancements.  So the police can see some cars but maybe they aren't a real "threat".  They might have already crossed an intersection and be about to go out of sight or be in a lane far away and about to pass the police car.  They might be several seconds ahead and not be a threat to an immediate collision. For that, the "time to collision" check code that the traffic utilizes was used here as well.  It does a collision prediction based on the velocities of the two vehicles using simple kinematics.  All of this information is then taken into account and a "threat score" is computed for that vehicle.  The threat scores of all the vehicles are then taken into account and a single normalized score from [0,1] is computed based on the results.  All of this is done in a separate behavior tree service so I can tick that at a different rate and keep it separated from the code that "reacts to" the threat.  This is a separate behavior tree service that takes the threat score and decides how much to slow down. 

Another area revisited was improved visual debugging. While tweaking the police AI I continued to enhance the "debug HUD" I use to visually see how the police are behaving.  Where are they moving to and how far away are they?  Diagnostic logs are nice but sometimes its easier to see the location on the screen with a green circle then look at an X,Y,Z coordinate in the logs.  Essentially the big three I use for debugging are 1) log statements that print to text files

2) Debug HUD that is toggled and draws simple primitives on screen to report info such as the context of the police chase

3) Console variables that are toggled that also print primitives on screen but can be toggled for a specific vehicle or just those close to the player and can be used to selectively show specific systems such as the spline path following.

A last kind of nerdy thing is continuing to increase usage of C++20 Concepts.  These are nice as they better constrain template code that I use heavily in a core module that has a lot of generic useful code. If there is a compiler error it is much more clear if it is detected with concepts.

Get Police Chase Simulator

Leave a comment

Log in with itch.io to leave a comment.