How do I Create and destroy Multiplayer Objects for all Peer

0 favourites
  • 3 posts
From the Asset Store
Background Story generation templates. See the Arcade demo.
  • How do you handle creating and destroying objects for all peers? I've read that the host must create the object and destroy the object, I've tried this many different ways and no success.

  • It depends on your method informing the peers of when objects need to be created.

    For instance, using the sync object.

    If you sync an object, and it gets created on the host, then it will automatically get created on the peers too.

    If the host destroys this object, it will be destroyed on all connected peers too.

    Using an in game event, for instance, a player joins.

    When a peer connects, you could use that moment to create an object for that given peer (or something in the level, whatever your fancy), without the need of synching the object, seeing as all connected peers will have the same "peer connected" moment.

    To have the object destroyed you would have to inform all connected peers through the host telling them a certain object needs destroying: see next examples

    Using the synched input state: a peer shoots and informs everyone.

    A peer presses a button to fire, setting a certain input state and this is relayed to the host by means of either a direct message, or based on the user input.

    The host receives the input state from the peer, and based on this creates the bullet at the peer.

    The input state goes for all peers, and all peer should create the bullet at the given peer based on the input state.

    As for destroying, should the bullet hit some target, the target could set an input state of destroyed=1

    All connected peers seeing the input state of the player who was hit, but the host destroys the object, and it gets destroyed on the other peers too. (synched object effect)

    Using a message: relatively simple but effective

    when a peer presses a button, it can simply send a message to a host, which relays it to the rest of the peers.

    For example:

    The host would process the following message from a peer AND broadcast it

    tag "shoot"

    message "bullet-100-100-360-400-peerid"

    (bullet-x-y-angle-speed-peerid)

    on tag shoot

    tokenat(Multiplayer.Message, 0, "-") = "bullet"

    create bullet at int(tokenat(Multiplayer.Message, 1, "-")) , int(tokenat(Multiplayer.Message, 2, "-")) on layer X

    bullet set angle int(tokenat(Multiplayer.Message, 3, "-"))

    bullet set speed int(tokenat(Multiplayer.Message, 4, "-"))

    set bullet.peerid = tokenat(Multiplayer.Message, 5, "-")

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • this is my current code for this problem, Something is still wrong because the peer can destroy the monster on the host screen but will not destroy on its own screen

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