Devlog 7


Car Spawning System

Once the core game mechanics were scripted and thoroughly tested—movement, turret control, shooting, cameras, it was time to try and tame one of the most significant multi-player systems: spawning player-controlled vehicles between scenes. Initially, our other coder had already completed the networking for the lobby system where the players wait and ready up. Once everyone was ready, they proceeded to the arena. The previous early coding, however, had one big issue: players spawned into the scene but possessed only a camera and no input control—vehicles were not being instanced, and player roles weren't being assigned properly.

 Basic Spawning

In response to this, I scripted a CarSpawnerManager, a spawn system that would create a car prefab per team and assign control roles (driver/shooter) based on player team and role selection. Players were spawned early on into a broad plane within the test lobby to start. The plane was massive and not very enclosed, so the spawn location wasn't an issue—we could drop cars anywhere and playtest things like shooting, driving, and taking damage.

During the playtesting, we were able to confirm the following  mechanics:

  1. Players could control just their specific roles
  2. They could shoot and deal damage to one another
  3. Switching  scenes without losing network ownership

After confirming the above mechanics, I started to set up a proper lobby environment for the players to spawn in and move around in the limited area. 

I incorporated a low-poly soccer field from the Unity Asset Store to utilize as the real lobby map. It improved the game visually but introduced a new issue: cars were spawning off the map or in the air. This was due to the fact that our old system did not consider terrain boundaries or physical barriers—it just picked random points. Since the new map was enclosed and had elevation, cars would spawn in the air.

Solution to the spawning problem

I looked into other solutions, but none of them in the literature had a formally established algorithm that directly tackled this type of dynamic, ground-aware spawning for multiplayer vehicle-based games. All the web examples I could find were for player capsules or used static spawn markers, which would not be feasible for our scale. Thus, I came up with my own solution—a Ground-Based Spawn Sampling Algorithm. Below is the pseudocode for that:



References

https://weisslog.com/unity/osnovy-unity/metod-raycasting-v-unity/

https://joneswanot1958.blogspot.com/2022/10/unity-raycast-hit-infinite-continue....

https://joneswanot1958.blogspot.com/2022/10/unity-raycast-hit-infinite-continue....