|
1 |
| -# TrafficSystemController-Unity |
| 1 | +# Traffic System Controller for Unity |
| 2 | + |
| 3 | + |
| 4 | +*An example of the Traffic System.* |
| 5 | + |
| 6 | +A Unity solution for simulating basic traffic behavior using waypoints. This system is designed for simplicity, making it ideal for quick prototypes or basic traffic implementations. |
| 7 | + |
| 8 | +## Features |
| 9 | +- **Waypoint-Based Movement**: Vehicles move along predefined paths using waypoints. |
| 10 | +- **Dynamic Route Selection**: Vehicles randomly choose paths at intersections. |
| 11 | +- **Collision Avoidance**: Vehicles detect and stop for others using raycasting. |
| 12 | +- **Customizable Speed and Behavior**: Configure vehicle speed, detection range, and stopping thresholds. |
| 13 | +- **Visual Debugging**: Waypoint connections are displayed in the scene view with Gizmos and labels for easy setup. |
| 14 | + |
| 15 | +## Installation |
| 16 | +1. Download the [`TrafficSystemController.unitypackage`](TrafficSystemController.unitypackage) file from this repository. |
| 17 | +2. Open your Unity project and go to **Assets > Import Package > Custom Package**. |
| 18 | +3. Select the `TrafficSystemController.unitypackage` file and click **Import**. |
| 19 | + |
| 20 | +## How to Use |
| 21 | +1. **Setup Waypoints**: |
| 22 | + - Add `WaypointController` to GameObjects in your scene. |
| 23 | + - Link waypoints by assigning `nextWaypoints` in the Inspector to define paths. |
| 24 | + |
| 25 | +2. **Add Vehicles**: |
| 26 | + - Attach the `VehicleController` script to your vehicle prefabs. |
| 27 | + - Assign the first `WaypointController` to the `currentWaypoint` property in the Inspector. |
| 28 | + - Specify the tag for vehicles (e.g., `Car`) in the `vehicleTag` field to enable collision detection. |
| 29 | + |
| 30 | +3. **Customize Behavior**: |
| 31 | + - Adjust vehicle speed, raycast distance, and stop time thresholds in the Inspector. |
| 32 | + - Set `nextWaypoints` for waypoints to control traffic flow. |
| 33 | + |
| 34 | +4. **Test Your Setup**: |
| 35 | + - Play the scene and observe vehicles navigating the waypoints. |
| 36 | + - Use Gizmos in the Scene view to visualize waypoint connections and debug traffic paths. |
| 37 | + |
| 38 | +## Visual Debugging |
| 39 | +- Waypoints are connected by green lines. |
| 40 | +- Blue spheres indicate the location of each waypoint. |
| 41 | +- Arrowheads show the direction of the paths, making it easier to identify connections in the Scene view. |
| 42 | + |
| 43 | +## Example Usage |
| 44 | +1. Place waypoints in a road network to define vehicle paths. |
| 45 | +2. Add vehicles and configure their initial waypoints and movement parameters. |
| 46 | +3. Vehicles will follow the waypoints, handle intersections dynamically, and stop for other vehicles when needed. |
| 47 | + |
| 48 | +## Limitations |
| 49 | +- Designed for simple traffic systems. More advanced behaviors (e.g., traffic lights) are not included. |
| 50 | +- Ensure waypoints are properly connected; disconnected waypoints will halt vehicle movement. |
| 51 | + |
| 52 | +## License |
| 53 | +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. |
0 commit comments