Best practices for multiplayer multi crew vehicles.

I’ve been looking around for some advice on how to implement multi-crew vehicles in multiplayer within Unity. Basically vehicles that exist as their own entity and players can hop in and out of positions on the vehicle to drive/shoot/etc. The advice I’ve found so far is very thin on the ground, vague, very outdated or refers to something in the assetstore ( that may or may not still exist ).

I’ve run pretty solidly up against the limits of my understanding of Unity multiplayer.

I’ve put together a reasonably functional implementation in singleplayer but I have no idea how to convert that into something that works within the constraints of multiplayer. For example, this is the current setup that I have:

Player(PlayerControllerScript)
Vehicle(VehicleControllerScript)
    Driver(DriverScript)(TriggerCollider)
    Gunner(GunnerScript)(TriggerCollider)

When the player hits a key when inside the trigger area of the driver/gunner the Player object becomes a child of the Driver/Gunner and is disabled, the driver script then takes over processing input from the player.

Vehicle(VehicleControllerScript)
    Driver(DriverScript)(TriggerCollider)
             Player(PlayerControllerScript)
    Gunner(GunnerScript)(TriggerCollider)

This works great in singleplayer but I have no idea how to pass input from the client to the server to tell it to move the player around. Am I at all on the right track or is there a much easier way of implementing this sort of thing?

Your input is much appreciated.

Sounds like you are on the right track. Not sure about the high level API, but these are some steps I would generally use for writing a low level protocol.

  • Player 1 parents their controller object to the vehicle object in their scene

  • Server tells everyone to parent the player driving to the vehicle in their scene
    +(Now in everyone’s instance of the game, player 1 is parented to the vehicle object)

  • The player driving now uses vehicle controls – just like an offline game – which moves the vehicle in their scene.

  • The person driving keep sending their position to the server as normal

  • The server should know that player X is now driving the vehicle – they should take that players position and relay it to the other clients as the vehicles position instead.

  • If you had other people join in they would parent the same way to the vehicle object.

  • But their movement would no longer be transmitted (except maybe rotations), since their character is receiving their movement as a child of the vehicle object.

  • Basically, get all the people parented to the vehicle object, and then the server is treating any positions from the person driving as the vehicles position.