Table of Contents

Multiplayer Setup

Mirror

Setup guide for NWH Vehicle Physics 2 multiplayer using Mirror framework.

Before starting make sure that your vehicle and scene are already set up for single-player. If not, check the Quick Start guide.

Setting up the scene

  • Create a new GameObject called 'NetworkMananger'.
  • Add the following components to the created object:
    • NetworkManager
    • NetworkManagerHUD
    • TelepathyTransport (or other transport if you are not using Telepathy). In newer versions of Mirror KcpTransport is the default.
  • Your object should look like this:

Setting up the vehicle

  • Double click on Mirror.unitypackage (NWH\Vehicle Physics 2\OptionalPackages\Multiplayer) to import the required assets.
  • Add MirrorMultiplayerVehicle component to the vehicle. This will also add necessary Mirror components automatically.
  • Make sure that NetworkTransform's Client Authority field is ticked.
  • Set Network Sync Interval to 0.05 (20Hz). Default value is 0.1 (10Hz) and is too low for physics objects and will result in stuttering.
  • Set Compress Rotation to None.
  • If you want to futher reduce stutter reduce all three Sensitivity field values.
  • Save the vehicle as a prefab and assign it to NetworkManager's Player Prefab field.
  • Your vehicle configuration should now look like this:

2023/05/14 16:35

Photon Unity Networking 2 (PUN2)

Setup guide for NWH Vehicle Physics 2 multiplayer using Photon Unity Networking 2 framework.

Make sure that your vehicle and scene are already set up for single-player. If not, check the Quick Start guide.

Check your Photon Unity Networking 2 setup with provided Photon demo scenes (e.g. slot cars) to verify that the Photon setup has been done correctly

Importing

  • Double click on PUN2.unitypackage (NWH\Vehicle Physics 2\OptionalPackages\Multiplayer) to import the required assets.

Adding PUN2 to the scene

  • Create a new GameObject and name it PhotonManager.
  • Add OnJoinedInstantiate and ConnectAndJointRandom to the newly created object.
  • Set position offset to some higher value (e.g. >10).
  • Set Auto Connect to true.

Adding PUN2 to the vehicle

  • Add PhotonMultiplayerVehicle component to your vehicle. This will automatically add other necessary scripts:

  • Make sure that under Photon View component Observe option is not set to Off. You can use any other option.
  • Observed Components should look as in the following image. If any component is missing from the list add it.

Instantiating

  • Objects that will be instantiated by OnJoinedInstantiate need to be placed under Resources folder. If you do not have such folder create one, its location does not matter. Drag your vehicle prefab to that folder.
  • Assign the vehicle prefab under Prefabs To Instantiate of OnJoinedInstantiate script.
  • Press Play. Vehicle will instantiate after a few seconds.
  • Build your project and open two windows side by side to test it out.
2023/05/14 16:35