Skip to content

A Unity-based racing game featuring an AI agent trained using Reinforcement Learning

Notifications You must be signed in to change notification settings

gabinollier/RacingGame

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RacingGame with AI

Unity ML-Agents

A Unity-based racing game featuring an AI agent trained using Reinforcement Learning (Unity ML-Agents).

📝 Description

This project demonstrates a racing game where an AI driver learns to navigate the track autonomously. The AI has been trained using Unity ML-Agents, allowing it to optimize its driving path and speed through reinforcement learning algorithms.

📂 Project Structure

  • Assets/: Contains the Unity project source code, scenes, scripts, and game assets.
  • results/: Stores the training results, including the neural network models (.onnx files) and TensorBoard logs generated by ML-Agents.
  • venv/: Python virtual environment containing the necessary dependencies for training the agent.
  • ML-Demos/: (Optional) Additional demos or configurations related to the ML environment.

🚀 Getting Started

Prerequisites

Installation

  1. Clone the repository:

    git clone [https://github.com/gabinollier/RacingGame.git](https://github.com/gabinollier/RacingGame.git)
    cd RacingGame
  2. Open the project in Unity:

    • Launch Unity Hub.
    • Click "Open" and select the RacingGame folder.
    • Wait for Unity to import the assets.
  3. Setup Python Environment (for training):

    • Ideally, create a new virtual environment to avoid conflicts, or use the provided venv.
    • Install the dependencies:
      pip install mlagents

🎮 Usage

Playing the Game

  1. Open the main scene located in Assets/Scenes/.
  2. Press the Play button in the Unity Editor.
  3. Watch the AI drive (or control the car using the PlayerController).

Training the AI

If you wish to retrain the agent or improve its performance:

  1. Open your terminal/command prompt and activate the Python virtual environment.

  2. Navigate to the project root.

  3. Run the ML-Agents training command:

    mlagents-learn config/trainer_config.yaml --run-id=RacingAI_01
  4. Press Play in the Unity Editor when prompted by the terminal.

🧠 AI Implementation

The AI uses a Reinforcement Learning approach where:

  • Observations: Raycasts (lidar-like vision), speed, and position.
  • Actions: Steering, acceleration, and braking.
  • Rewards: Positive rewards for moving forward/staying on track, negative rewards for hitting walls or going off-track.

About

A Unity-based racing game featuring an AI agent trained using Reinforcement Learning

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published