Search Unity

Changing current player object

Discussion in 'Multiplayer' started by Deimantas69, Oct 20, 2017.

  1. Deimantas69

    Deimantas69

    Joined:
    Mar 13, 2016
    Posts:
    3
    In an open world setting, where I already have a vehicle and a player spawned, I want the player to be able to possess the vehicle or vice-versa without writing a separate player controller for handling input.

    The server has this code which does the job fine while the host, but as soon as I try this as a client it quickly overflows the connection causing the client to timeout:

    Code (CSharp):
    1.     public void ChangeOwnership(NetworkConnection ConnectionToClient, GameObject NewObject, short PlayerControllerId, GameObject OldObject, CarController TempFocusedObject)
    2.     {
    3.         if (isServer)
    4.         {
    5.             TempFocusedObject.PossessVehicle();
    6.             NetworkServer.ReplacePlayerForConnection(ConnectionToClient, NewObject, PlayerControllerId);
    7.             OldObject.SetActive(false);
    8.         }
    9.     }
    Is there any way in which I could change the player object much more easilly?
    Edit: upon adding if(islocalplayer) to the vehicle the car no longer moves which means it doesn't get replaced for the connection
     
  2. Deimantas69

    Deimantas69

    Joined:
    Mar 13, 2016
    Posts:
    3
    Right, so I ended up making a decision to instead use a charactercontroller that can posses the object and execute functions on it