This document is about: QUANTUM 2
SWITCH TO

AI


Available in the Gaming Circle and Industries Circle
Circle

Overview

  • The Racing AI uses a “Chase the rabbit” navigation approach and an HFSM for decision making
  • Multiple AI difficulty setups are available (Very Easy, Easy, Normal, Hard, Extreme)
  • The driving line for AI navigation supports multiple lines, per-difficulty lines and line branching
  • The AI is never controlling the car position or rotation directly. It is generating input which is then processed in exactly the same way as input from real players would be.

Rabbit

Arcade Racing AI uses the Chase the rabbit (or Follow the rabbit) AI technique. The "rabbit" runs ahead of the car and the car is trying to chase / catch up with it. In the Arcade Racing template, the rabbit is simply an empty entity which is either moving along the driving line or being controlled by a NavMesh agent. The AI then generates input based on the direction and distance from the car to the rabbit.

Movement

The rabbit does not have to move fluently. It can jump from one point to another, accelerate or decelerate without taking physics into account and goes into turns before the car does. All these aspects help with managing the complexity of AI car handling. Simply send the rabbit to some point and the car will follow it believably.

Note: The Rabbit usually does not exactly follow the driving line but rather uses an offset to it based on the AIConfig values to achieve a more natural behaviour.

The rabbit usually runs at the car's max speed. It can speed up if the car is going faster (e.g. using Nitro) or wait for the car if the rabbit is too far ahead of it. When the rabbit is further than a certain distance, it can also be snapped instantly in front of the car.

When the rabbit is getting closer to the car (e.g. slowing down according to driving line speed), the AI will alter the input to slow down to avoid getting ahead of the rabbit. Therefore the rabbit effectively dictates the desired max speed.

Visuals

To display the rabbit entity, search for the AIRabbit prefab and enable its MeshRenderer component.

ai rabbit
Car with a rabbit represented by a red sphere.

Driving line

The driving line is a set of points that describe where the car should drive; or more specifically, where the rabbit should run. Each point can have a difficulty and speed multiplier to alter which line will an AI choose and how fast it will go when passing the point.

driving line
Driving line (green).

The driving line is baked into the Gameplay scene entity during the scene map baking process. See the Driving Path Editor section for more details.

There could be multiple lines with different difficulties, lines representing a shortcut or simply just an alternate way of driving through a turn.

driving line branching
Driving line branching.

Line points do not have to be precisely positioned. A line's start and end points will be merged with the nearest line during the baking process.

HFSM

The Arcade Racing Sample's AI is quite simple in terms of decision making. It is only used to decide when to use Nitro.

hfsm
HFSM.

Follow Line Action

The FollowLineAction sets the destination for the rabbit when it has reached the target destination. The destination itself is set based on the player checkpoints.

Note: There is no pathfinding on the driving lines currently. The rabbit simply assumes it will get to the target destination by following the line.

AI Difficulties

AI difficulty is defined via the AIConfig and AIHandling assets.

  • AIConfig is used to control the configuration values of the HFSM and to modify the rabbit's behaviour around the driving line.
  • AIHandling is responsible for generating AI input. The AIHanding class can be inherited from to create a completely custom AI handling behaviour.
ai assets
AI assets.
Back to top