Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

All users both client and server able to move same object

Discussion in 'Multiplayer' started by tezer86, Jun 29, 2014.

  1. tezer86

    tezer86

    Joined:
    Jul 19, 2010
    Posts:
    90
    Hey All,


    I am making a game where all players are able to change the location of the same cube. However I get an issue where the cube can only be moved by the user who instantiated it. Does anyone know a way to get the behaviour I require?

    Many thanks

    Terry
     
  2. CheetahSpeedLion

    CheetahSpeedLion

    Joined:
    Jun 29, 2014
    Posts:
    13
    From what I understand only the owner of the networkViewID is able to control any given object unless you use some fancy RPC's to communicate input between the different players. If you're using an authoritative server setup where all the cubes are instantiated in the server, then any client can send its input to the server and the server can move the cube.
     
  3. Magiichan

    Magiichan

    Joined:
    Jan 5, 2014
    Posts:
    395
    Show us your code.
    Note that you don't want to use the built-in position sync.
    Use RPC's for that stuff.
     
  4. tezer86

    tezer86

    Joined:
    Jul 19, 2010
    Posts:
    90
    Hey Cheetah,
    Thanks for the reply.

    Yeah this seems to be my findings as well, been doing a lot of reading about this and it seems the best way is what you describe, pretty much have the host own all objects. Then clients request to move the objects and somehow the host then does that and sends it to the clients. Im assuming this is on a case by case basis as stuff like bullets or missiles, the Client can network instantiate.


    So the Host owns a Ship for example and also owns all the variables associated with that game object (Ship). If a Client changes the speed of the ship then I need to send a request to the server to change it, then the server sends out that RPC to all other Clients.

    I think thats the bit I'm finding it hard to get my head around, how do I send a message to the Host to change the speed of the ship, it would be good to get a my first programming kind of flow chart on how some of this stuff works, I'm quite a visual person. Though I suppose I will just muddle on until I get it working.


    Networking just seems like something that needs to be planned out right before you start coding, otherwise there will be lots of pitfalls later.

    Cheers
    Terry
     
  5. tezer86

    tezer86

    Joined:
    Jul 19, 2010
    Posts:
    90
    Hey,

    Thanks also for the reply. I haven't written much in code yet as I want to plan out how I'm going to work everything, I just have a simple cube with a network view on and noticed that only the host could move the cube and have it synced to other players. Is that what you mean by the 'built in position sync'?

    Cheers
    Terry
     
  6. tezer86

    tezer86

    Joined:
    Jul 19, 2010
    Posts:
    90
    Hey Magiichan,

    I think I get what your saying, but wanted to make sure I was understanding correctly. In the following link it says about using RPC and turning of state sync:

    http://docs.unity3d.com/ScriptReference/NetworkView.RPC.html

    So then anyone can move an object even someone who isn't the owner and send an RPC to Others and they all get update

    Cheers
    Terry
     
    Magiichan likes this.