0 Favourites

How do I Sync multiple objects between 2 or more players

  • Hi all

    I'm working on a "simple" RTS, using the default multiplayer plugin. Thus far, I have my lobby / room all setup and it works just fine. Furthermore, I'm switching layouts for maps, while the host / peers remain connected. This too works fine. However, I'm having some issues with sync. object.

    Setup

    In my setup, I'm doing the following:

    1. I sync. a Family called Units (position and angle)

    Multiplayer -> Sync. Units (Family) with Position and angle, precision Low (int16, 2 bytes) at Normal bandwidth
    [/code:6w9f2ae1]
    
    2. When a unit is created, it is associated with [b]Multiplayer.PeerId[/b] for both the Host and the Peer side.
    
    [code:6w9f2ae1]
    Units (Family) on created:
                       Units (Family) -> Set peerId to Multiplayer.PeerID
                       Multiplayer -> Associate Units (Family) with Multiplayer.PeerID
    [/code:6w9f2ae1]
    
    [b]Creating Units[/b]
    
    1. The host is creating a single unit per peer, on layout start
    
    [code:6w9f2ae1]
    System for each Player (Sprite that represents peer)
                      Create object "Worker" (Part of Units Family) on layer "units" at (posX, posY)
                      "Worker" set peerId to Player.peerId
    [/code:6w9f2ae1]
    
    2. The host is responsible for some path finding / moving
    
    [code:6w9f2ae1]
    N/A - Not important in this context.
    [/code:6w9f2ae1]
    
    This all works well enough - just a very small delay in unit movement, on the peer side.
    
    [b]Problem Creating Multiple Units[/b]
    
    1. The host creates two (or more) units per peer, on layout start
    
    [code:6w9f2ae1]
    function createWorker(peerId, posX, posY)
                      Create object "Worker" (Part of Units Family) on layer "units" at (posX, posY)
                      "Worker" set peerId to peerId
    
    System for each Player (Sprite that represents peer)
                      call "createWorker" (Player.peerId, 100, 100)
                      call "createWorker" (Player.peerId, 150, 100)
                      ...etc
    [/code:6w9f2ae1]
    
    While the host appears to have everything in order, all peers mess this completely up. The units are created on the host and the peers. Yet they are not associated with themselves on the peer side. The peers gain control (association) with at most a single unit, which was assigned to them.
    
    Does anyone have an idea why?
    Must I really sync. the native object, instead of a family in my setup... Or must I invoke sync. object per created instance (seems unlikely)? Should the host wait some given interval before creating unit number 2, 3.. etc, per peer?
  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • With multiple units of the same family/object you can not associate objects with peerid, that only works if each peer has just one of those objects.

  • Okay, sure - I guess that makes somewhat sense of the issue that I'm facing. However, how - if at all possible - can I control multiple units of the same type object, per peer?

    I mean that, for my game, each player should be able to have multiple "worker", which I somehow must sync their position, state and perhaps a few other properties, e.g. health.

  • Okay, sure - I guess that makes somewhat sense of the issue that I'm facing. However, how - if at all possible - can I control multiple units of the same type object, per peer?

    I mean that, for my game, each player should be able to have multiple "worker", which I somehow must sync their position, state and perhaps a few other properties, e.g. health.

    Yes that definitely works, I have a template in the arcade with downloadable capx

    https://www.scirra.com/arcade/multiplay ... -746?cp=12

  • Aha, I see. Thanks mate - your template is a very good inspiration for what I wish to achieve.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)