Final Presentation
(1) The main idea of the project and core aspects.
We wanted to create a realistic freeway and simulate the behaviour of cars and the creation of traffic jams as well as the changing of lanes.
To do this, we:
- Check neighbours forward and backwards using the x position (in two different loops) inspired from the code doing that in lab 2.
- Since we spawn our cars frequently, we need to make sure that when they spawn they keep a safety distance at first (to avoid them spawning on top of each other), the car in the back will slow down its speed until it is within a safe radius.
- We are using two different radiuses. The biggest one is used for detecting neighbours within that radius (radius). The other one is minradius. If a car is within the minradius, they need to slow down untll they are in outside of minradius.
The radiuses are illustrated in the follwing image:
- When a car is detected within radius, it starts to slow down. This is done by interpolating the speed till it matches the neighbouring car if the neighbouring car is slower. We do this with the help of the Unity Lerp function.
- When a car starts to slow down it will try to change lane to the left. If that lane is free. This is done by checking if there is a car in the y position at the given coordinates of the neighbouring lane, the same way as checking neighbours front and back.
- Cars that are in the outermost left will try to change lane to the right if they are too slow. We do this by checking if the car behind (with the help of radius) has a higher starting velocity. If it does, the slower car will change lane to the right if the lane is free. The car that was behind, that had to slow down, will accelerate back to its starting velocity, with the help of the Lerp function.
Problems we encountered:
- We tried to get the cars to lerp sideways while changing lanes, instead of teleporting as they do now, but the values we need to lerp between are so small that the car doesn’t go all the way. It did work if we used Time.deltatime*1000, but it interpolated to fast and it still looks like it teleports. A solution to this would be to give the car a velocity in the y direction, but the way our code is built and how it checks neighbours, we wouldn’t be able to detect the cars that are in between lanes.
- We also discovered that since we use floats, there are a few bugs with the floating points (flyttalsfel) so we have put in place a few safety measures.
(2) Your progress and where the project is now. A pre-recorded demonstration is the best way (if you have one), otherwise work in progress screenshots.
Here is a video of the freeway simulation:
(3) The approximate grade you are aiming for.
We are aiming for a pass.