Local Multiplayer


After refining the player movement, it was time to extend these controls to a second player. Unity’s new Input System includes a Player Input Manager, that is designed to allow for easy implementation of local multiplayer, by automatically joining a player to the scene for each separate input device. While this drop in/drop out style of multiplayer worked as a proof of concept, several issues arose surrounding the join order of players, often with the delegation of a single controller to multiple instances of a player. As the plan was to extend local multiplayer to up to four players, it was necessary to write a script to manually spawn each player and assign separate input devices to each. As the game currently lacked a UI or menu system at this stage, the player ships were simply spawned in sequentially at the start of the game, so that each input instance was assigned correctly. Initially, each player had a fixed spawn point, but this allowed for spawn camping. So, the hyperdrive script was modified to handle initial spawns and respawns, randomizing the position each time. The trade-off, however, is the narrow possibility of spawning on or near the central star, or another player.


With local multiplayer now working, it became apparent that the addition of more players would quickly outgrow a fixed screen area. To fix this, a dynamic camera was created that tracks each player, moving and expanding the viewport to keep everything in frame. While this could have been implemented using the Cinemachine group camera, I instead decided to write a custom script to handle camera tracking, to limit external package dependencies, and correct some visual jitter caused by a discrepancy between the player and camera movement.