Skip to content

Four Way Traffic Simulator with Lights & Vehicles Following Traffic Rules

Notifications You must be signed in to change notification settings

WillKirkmanM/traffic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Traffic

Four Way Traffic Simulator with Lights & Vehicles Following Traffic Rules

Features

  • Intersection with Traffic Lights: Four-way intersection with coordinated traffic lights
  • Vehicle AI: Vehicles that react to traffic lights and avoid collisions
  • Realistic Movement: Vehicles accelerate, decelerate, and stop based on traffic conditions
  • Visual Feedback: Color-coded traffic lights and directional vehicles

Traffic Light Algorithm

The simulation implements a simple time-based traffic light algorithm:

  1. Coordination: East-west and north-south lights are coordinated to avoid conflicts
  2. Cycle: Each light cycles through Red (5s) → Green (5s) → Yellow (2s) → Red
  3. Priority: When east-west lights are green, north-south lights are red and vice versa

Vehicle Behavior

Vehicles in the simulation exhibit several intelligent behaviors:

  • Stop at red and yellow traffic lights
  • Maintain safe distances from other vehicles
  • Accelerate when the path is clear
  • Travel at different speeds (randomized for each vehicle)
  • Automatically despawn when out of view

Running the Simulation

Prerequisites

  • Rust and Cargo (1.39 or newer)

Installation

  1. Clone this repository
git clone https://github.com/WillKirkmanM/traffic.git
  1. Build and run:
cargo build --release
cargo run --release

About

Four Way Traffic Simulator with Lights & Vehicles Following Traffic Rules

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages