In our previous video, we showed how to network a character in just five minutes. Now, we’re taking it a step further by adding vehicles, complete with both a driver and a passenger.
You can download the sample project to explore the scripts further and follow along.
Subscribe to our Youtube channel for more videos like this!
The demo starts with a fully offline vehicle Prefab. It includes a vehicle controller script that handles motion and physics, and a vehicle script that manages player interaction. When a player approaches, the script checks if the vehicle can be used. If the interaction is confirmed, the player’s input is switched off, and the vehicle’s input is enabled.
To network the vehicle, we add the coherence Scene component. Important steps include marking the vehicle as unique (so it doesn’t duplicate for each player) and persistent (so it remains when an authority leaves). Authority is then transferred to the next connected player.
Next, we implement logic for becoming the driver. This involves authority requests, callbacks like OnAuthorityRequested, and syncing variables such as hasDriver. The system ensures smooth authority transfers, even if multiple players request control at the same time.
Passengers are handled differently. Instead of requesting authority, they send a network command. This allows them to be parented to the car, adjust the camera, and ride along without taking control. Variables like hasPassenger are synced across Clients to prevent conflicts.
This tutorial highlights key Coherence concepts: authority, authority transfer, network commands (RPCs), and synced variables. Together, they create reliable multiplayer interactions for shared vehicles.
Don't forget, you can download the sample project for this tutorial.
Stay tuned for more tutorials and subscribe to our Youtube channel if you don't want to miss them.
Written By