NWH Vehicle Physics 2
Search Results for

    Show / Hide Table of Contents

    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 MIRROR define, which Mirror sets automatically). Import the sample before installing Mirror and MirrorMultiplayerVehicle won't appear.

    Import Sample

    1. Open Package Manager (Window > Package Manager)
    2. Select "NWH Vehicle Physics 2" from the list
    3. Navigate to the Samples tab
    4. Import "Multiplayer Mirror Sample"

    Scene Setup

    Create a NetworkManager GameObject:

    • Add NetworkManager component
    • Add NetworkManagerHUD component (for testing)
    • Add KcpTransport component (or other transport)

    Vehicle Setup

    1. Add MirrorMultiplayerVehicle component to your vehicle
      • This automatically adds required NetworkIdentity component
    2. Add ONE physics sync component:
      • NetworkTransformReliable - syncs position/rotation only
      • NetworkRigidbodyReliable - syncs full physics state (recommended)
    3. Save vehicle as prefab
    4. 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:

    1. Open Package Manager
    2. Select NWH Vehicle Physics 2
    3. Expand Samples section
    4. Import Multiplayer PUN2 Sample

    Scene Setup

    Create a PhotonManager GameObject with:

    • OnJoinedInstantiate component
    • ConnectAndJoinRandom component
    • 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.

    In this article
    Back to top Copyright © NWH - Vehicle Physics, Aerodynamics, Dynamic Water Physics