Goals
[Expand]

Environment And Tracks
[Expand]
The karting agent observes a compact state vector, drives with continuous control, and is rewarded for fast, clean progress through checkpoints. The default training scene is Assets/Karting/Scenes/KartingChallenge.unity.
| Training Track | Karting Agent |
|---|---|
![]() |
![]() |
| Component | Description | Dimension / Type | Notes |
|---|---|---|---|
| Action | Continuous control: steer, brake, accelerate | 3 values (continuous) | 3D continuous control. |
| Observation (State) | 9 lidar distances + speed + direction + distance to next collider | 12‑dimensional vector | Vector observations only. |
| Reward | Multi‑objective | Scalar | Avoid collisions, pass checkpoints, move toward checkpoints, move fast. |
| Track layout | Single training track provided | N/A | Meta‑goal: generalize to other tracks. |
Training Variants
| Training Easy | Training Medium | Training Hard |
|---|---|---|
![]() |
![]() |
![]() |
These variants are available as scenes under Assets/Karting/Scenes/Train/.
Quick Start
[Expand]
2021.3 LTS can be installed through the Unity Hub).Assets/Karting/Scenes/KartingChallenge.unity.Note: For manual driving, insert the keyboard agent from Assets/Karting/Prefabs/KartClassic/.
Installation
[Expand]
You can install the repo as a Python package for the Unity environment wrapper.
pip install . or pip install -e .pip install .[training]Training
[Expand]
This project is designed to work with Unity ML‑Agents. A typical flow:
If you add new track parts, ensure the reward logic and collision handling still behave correctly across them.
Build The Training Environment (Unity Executable)
Training uses a standalone Unity build (not the editor). Build it once and reuse it for runs.
| Platform | Build Output |
|---|---|
| Windows | Training/KartingChallenge.exe |
| macOS | Training/KartingChallenge.app |
| Linux | Training/KartingChallenge.x86_64 |
File > Build Settings….Build.Training/KartingChallenge (see table below).Training (Python)
To train a Karting Agent using Stable Baselines 3 use:
from stable_baselines3 import PPO
from KartingGymnasium import *
# Setup karting environment, pass the path to your build executable
# Use time_scale to increase the simulation speed, no_graphics for running headless
env = KartingGymnasium("./KartingChallenge", time_scale=10, no_graphics=True)
# Setup model, log to tensorboard and train
model = PPO("MlpPolicy", env, verbose=1, tensorboard_log="./tensorboard")
model.learn(total_timesteps=10e5)
# Save the model for later inference
model.save('models/KartingModel')
env.close()
Gymnasium Wrapper
The KartingGymnasium package exposes a Gymnasium-compatible environment around the Unity build. It connects via ML‑Agents, provides a standard reset()/step() loop, and supports continuous actions only.
Export Policy (ONNX)
To export a trained SB3 model to an ONNX "brain" for inference in Unity, use:
from stable_baselines3 import PPO
from KartingGymnasium import *
# Load model, create karting brain, and export
model = PPO.load('models/KartingModel')
brain = KartingBrain(model)
brain.export("models/KartingModel.onnx")
To use the model, move it to Assets/Karting/Prefabs/AI.
In Unity, with the Scene open, select the KartingAgent; in the inspector under Behavior Parameters > Model select your model.
Pressing play in the editor should start the scene and the agent running in inference using the behavior from the trained model.
KartingGymnasium/wrapper.pyKartingGymnasium.KartingGymnasiumTournaments
[Expand]
In addition to the training track specified above, there are predefined tournament scenes.
Tournament scenes live under Assets/Karting/Scenes/Tournament/.
These scenes contain multiple agents preconfigured with different models for head‑to‑head evaluation.

Tournament Layouts
| Tournament Easy | Tournament Medium | Tournament Hard | Tournament Advanced |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
Keyboard Agent
A keyboard agent is included for manual driving and camera following. Use the arrow keys to drive and the spacebar to swap between agent cameras and the bird’s‑eye view. The keyboard and karting agents are available as prefabs under Assets/Karting/Prefabs/KartClassic/.
Adapting Parameters
[Expand]
In Unity, select a karting agent and adjust parameters in the Inspector under Karting Agent:
New tracks can be assembled from parts in Assets/Karting/ModularTrackKit/Prefabs/.
Citation
[Expand]
When using this repository you can cite it as:
@software{kartingchallenge2023,
title = {Karting Challenge},
author = {Philipp Altmann and Maximilian Zorn and Jonas Nüßlein and Fabian Ritz and Andreas Sedlmeier and Thomy Phan},
version = {0.8.0},
year = {2023},
url = {https://github.com/philippaltmann/KartingChallenge}
}








