2D Racing Game: Part 2

Today I am continuing on with my 2D unity game. Straight away I bumped into problems with the collisions.

I needed to change the way the car moved in order for it to be able to collide correctly with the barriers of the track. I changed it from a transform.position  movement to a rigidbody velocity movement.

This then allowed the car to collide correctly.

ezgif-3863606766

I then added some enemy cars and set them to spawn above the screen, and then to drive down. However, they both seem to spawn at the exact same time, so I needed to change the spawn location and add some randomness.

ezgif-799581679.gif

I added a spawn location and made it so that the prefab will be randomly spawned between two set positions, so that the cars stay on the track.

However, I now need to add a timer so that they spawn at different times and multiple times.

ezgif-1339660066.gif

What I needed to do was to paste the code instead of being in the start function, but into the update function. But this meant that the cars spawn every single second.

ezgif-1607373711.gif

This is the reason that a timer is needed to control the spawning of the cars.

ezgif-189373390.gif

Leave a comment