MGMLaboratory
Back

Menu

01Home
02About Us
03Projects
04Publications
05Member
06Articles
07Contact

Let's Talk

Open in Mail app

Socials

Malang (ID) --:--Privacy PolicyTerms of Service

June 27, 20212 min read

Giving a Kart Racing Game an Opponent to BeatGiving a Kart Racing Game an Opponent to Beat

A decision tree and a line of waypoints turned a solo template into a race.

  • Journal
  • Publications

Written by

  • SRShirasaka RenIT & Infrastructure · Student Member

In this article

  1. 01Driving, then deciding
  2. 02How it tested

A racing game with nobody to race gets old fast. That was the problem with a Unity karting template a team of developers picked up in 2021. It could only be played alone, because it shipped without an opponent. Their fix was to build a non player character that drives the course and competes for position.

A racing game setup at a gaming event. Image: Hilary Murugu, CC BY-SA 4.0, via Wikimedia Commons.
Fig. 01A racing game setup at a gaming event. Image: Hilary Murugu, CC BY-SA 4.0, via Wikimedia Commons.

The work split into two separate problems. The kart has to move around the track without clipping walls or barriers, and it has to choose what to do when the track ahead changes. Both need to run cheaply enough that the frame rate holds.

01/02

Driving, then deciding

For movement, the team placed waypoints along the track and let the NPC steer between them. A raycast, a line cast forward from the kart to see what it touches, watches for obstacles and triggers a correction when something blocks the path.

  • Waypoints tell the kart where the road goes.
  • A decision tree tells it what to do next.
A decision tree branching toward outcomes. Image: Lapollard, CC BY-SA 4.0, via Wikimedia Commons.
Fig. 02A decision tree branching toward outcomes. Image: Lapollard, CC BY-SA 4.0, via Wikimedia Commons.

02/02

How it tested

The team ran black box testing to check behaviour from the outside, and white box testing to check the logic inside. Both passed. They also drove the NPC for ten laps to watch how it handled corners and contact with other karts.

The performance cost turned out to be small. Adding opponents in pairs cost roughly 0.2 to 0.3 frames per second, so a race can hold several of them on modest hardware without a visible drop.

On lap time, the new NPC beat the machine learning opponent that came with the template. The authors argue the decision tree is the cheaper route, since it needs no training data and its behaviour can be read straight off the rules.

One game and one track is a narrow test, so the exact figures will not carry over to another project. The structure will. Racing AI is easier to build when driving and deciding are solved separately.

Source

  1. Mas'udi et al. (2021). Development of Non-Player Character for 3D Kart Racing Game Using Decision Tree. Fountain of Informatics Journal.

    DOI10.21111/fij.v6i2.4678 (opens in a new tab)

Next articleBuilding a Racing Opponent from Waypoints and Rules(Keep scrolling)(Read it next)(Loading)