Multiplayer Setup
Set up and test the vehicle in single-player first. Multiplayer adds vehicle-state synchronization and your networking package's physics synchronization to that working vehicle.
v14 includes samples for Mirror and Photon PUN2. Install the chosen networking SDK before importing its sample. Both multiplayer samples also require NWH Common > Common Base Sample, then the Vehicle Physics Base Sample and Mobile Sample. Import them from the Package Manager's In Project list.
Use the sample scene to check that two instances can connect before changing your own scene. The vehicle-state component sends controls, gears, lights and engine state; transform and Rigidbody synchronization still belong to the networking framework.
Mirror
NWH Vehicle Physics 2 multiplayer setup with Mirror.
Requirements
- Mirror networking package installed
- Vehicle already set up for single-player
Install Mirror first. The sample compiles only when Mirror is present (its asmdef is gated on the
MIRRORdefine, which Mirror sets automatically). Import the sample before installing Mirror andMirrorMultiplayerVehiclewon't appear.
Import Sample
- Open Package Manager (Window > Package Manager)
- Select "NWH Vehicle Physics 2" from the list
- Navigate to the Samples tab
- Import "Multiplayer Mirror Sample"
Scene Setup
Create a NetworkManager GameObject:
- Add
NetworkManagercomponent - Add
NetworkManagerHUDcomponent (for testing) - Add
KcpTransportcomponent (or other transport)
Vehicle Setup
- Add
MirrorMultiplayerVehiclecomponent to your vehicle- This automatically adds required
NetworkIdentitycomponent
- This automatically adds required
- Add ONE physics sync component:
NetworkTransformReliable- syncs position/rotation onlyNetworkRigidbodyReliable- syncs full physics state (recommended)
- Save vehicle as prefab
- Assign prefab to NetworkManager's Player Prefab field
How It Works
MirrorMultiplayerVehicle synchronizes vehicle state at 20Hz:
- Inputs (steering, throttle, clutch, handbrake)
- Gear shifts
- Light states
- Engine RPM
Physics (position/rotation/velocity) are handled by Mirror's NetworkTransform/NetworkRigidbody components.
Works in both dedicated server and host+client modes.
Photon Unity Networking 2
Multiplayer implementation for NWH Vehicle Physics 2 using Photon Unity Networking 2.
Prerequisites
- Vehicle and scene must be set up for single-player first (see Quick Start)
- PUN2 must be imported and configured (verify with Photon's demo scenes first)
Setup
Import Sample
Import the Multiplayer PUN2 Sample via Package Manager:
- Open Package Manager
- Select NWH Vehicle Physics 2
- Expand Samples section
- Import Multiplayer PUN2 Sample
Scene Setup
Create a PhotonManager GameObject with:
OnJoinedInstantiatecomponentConnectAndJoinRandomcomponent- Set position offset >10
- Enable Auto Connect
Vehicle Setup
Add PhotonMultiplayerVehicle component to your vehicle. This automatically adds required components:
- PhotonView
- PhotonRigidbodyView
- PhotonTransformView
Important: PhotonView's Observe option must NOT be set to "Off".
The component automatically configures ObservedComponents on initialization. Configurable properties:
- Send Rate: Network send rate (default: 12)
- Serialization Rate: State serialization rate (default: 12)
Instantiation
Place vehicle prefab in a Resources folder, then assign it to PhotonManager's OnJoinedInstantiate > Prefabs To Instantiate.
Press Play to test. For multiplayer testing, build the project and run two instances side by side.
How It Works
PhotonMultiplayerVehicle implements IPunObservable to synchronize:
- Input states (steering, throttle, clutch, handbrake, gear shifts)
- Light states
- Engine angular velocity
- Actions (horn, engine start/stop, cruise control, boost, flip over, trailer attach/detach)
The PhotonView owner simulates physics. Remote clients receive and apply the synchronized state.
Other networking systems
A custom integration needs to determine which instance owns the vehicle, exchange GetMultiplayerState() / SetMultiplayerState() data and supply physics synchronization. Set remote ownership after vehicle initialization. See the multiplayer API and the included sample scripts for the ownership and serialization details.