Search Unity

Network Object Transform Motion Control

Discussion in 'Multiplayer' started by Zullar, Aug 29, 2016.

  1. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    I am working on a overhead action RPG.


    I am struggling how to properly set up the object's networked structure and control motion. Most objects will be controlled by server while running physics locally on each client in-between network updates. Except for the client player character, which will be controlled by the client (client --> server --> other clients).

    I believe I need to generate a custom script similar to NetworkAnimator to send motion information. But every option has problems and I'm not sure what to do.
    1: NetworkTransform doesn't work because it's glitchy and you can't sync NetworkAnimator from Server --> Client while also syncing NetworkTransform from Client --> Server (because NetworkIdenity.hasAuthority is used for all components). Also for my game I need to send commanded velocity, max rotate speed, commanded angle, etc. to locally perform physics and rotation on the object until the next network update is received.
    2: SyncVar's do not work because they cannot be sent from Client --> Server
    3: OnSerialize/OnDeserialize cannot be used because they cannot be sent from Client --> Server
    4: Messages: If I use messages then after an object is spawned it will be at the wrong angle/velocity until the 1st message is received to correct it. Late connecting players will also have incorrect motion information until the first message is received. Unless I did something like this.
    -Instantiate object on server (disabled)
    -Spawn object (disabled)
    -Send message to update position/velocity/angle/etc.
    -Once message is received then enable object locally on each client
    5: Commands/RPC's do not work similar to messages because newly spawned objects will be at the wrong angle/velocity momentarily until the first command/RPC is received and the object is corrected. For late connecting players everything will be at the wrong positon/rotation until updated. Unless (as above) it is disabled until the first command/RPC is received.

    My best idea is to use SyncVars or OnSerialize to send information from Server --> Clients, and then for the player character I will use Commands/Messages to send information to Server (and then ignore this information when it sent back to the controlling player). But this seems complex, convoluted, and wrong.

    Any ideas on the best way to set this up? Thanks in advance.