NWH Vehicle Physics 2
Search Results for

    Show / Hide Table of Contents

    Photon Unity Networking 2 (PUN2)

    Multiplayer support for NWH Vehicle Physics 2 using Photon Unity Networking 2.

    Note: Requires the Multiplayer PUN2 Sample to be imported via Package Manager. Ensure your vehicle and scene work in single-player before adding multiplayer.

    Install PUN2 first. The sample compiles only when PUN2 is present (its asmdef is gated on the PUN_2_OR_NEWER define, which PUN2 sets automatically). Import the sample before installing PUN2 and PhotonMultiplayerVehicle won't appear.

    How It Works

    Works with host + clients and dedicated server setups. The key principle: whoever owns the PhotonView simulates the physics. Remote clients receive state updates via PhotonRigidbodyView, PhotonTransformView, and custom vehicle state synchronization.

    Synchronized State:

    • Transform and rigidbody (position, rotation, velocity)
    • Input (steering, throttle, clutch, handbrake, shifting)
    • Engine RPM
    • Lights state
    • Module actions (horn, boost, cruise control, flip over, trailer attach/detach)

    Setup

    1. Import Sample

    Import Multiplayer PUN2 Sample via Package Manager > Vehicle Physics 2 > Samples.

    2. Configure Photon

    Set up PUN2 in your project following Photon's documentation. Test with Photon's demo scenes first to verify correct setup.

    3. Add to Vehicle

    Add PhotonMultiplayerVehicle component to your vehicle. This automatically adds required components:

    • PhotonView
    • PhotonRigidbodyView
    • PhotonTransformView

    PhotonMultiplayerVehicle Properties:

    • Send Rate (default: 12) - Network updates per second
    • Serialization Rate (default: 12) - State serialization frequency

    4. Configure PhotonView

    • Set Observe Option to any value except Off
    • Set Observable Search to Manual
    • Observed components are automatically configured on initialization

    5. Place in Resources

    For runtime instantiation, place the vehicle prefab in a Resources folder (any location).

    6. Test

    Build and run two instances to test multiplayer. The demo scene includes example Photon manager setup.

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