Four Way Traffic Simulator with Lights & Vehicles Following Traffic Rules
- 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
The simulation implements a simple time-based traffic light algorithm:
- Coordination: East-west and north-south lights are coordinated to avoid conflicts
- Cycle: Each light cycles through Red (5s) → Green (5s) → Yellow (2s) → Red
- Priority: When east-west lights are green, north-south lights are red and vice versa
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
- Rust and Cargo (1.39 or newer)
- Clone this repository
git clone https://github.com/WillKirkmanM/traffic.git- Build and run:
cargo build --release
cargo run --release