[Online multiplayer question] Syncing Objects

Discussion and feedback on Construct 2

Post » Wed Jun 08, 2016 9:00 am

Image

I was messing around with Construct 2's multiplayer and it was going pretty okay for a while.
I was making a top-down cooperative dungeon crawler and things were going okay, but he main thing I was fighting the whole time was the lack of responsive controls for peers when I was following the multiplayer online tutorial.
Even with the predictive movement, peers were jittering around after having stopped moving which annoyed me to no end.

I'm not really concerned with cheating in a cooperative game, which was what was discussed in the tutorial, so I had to implement some workarounds where the peer sends data to the host (for movement) and the host syncs it back where it updates your position for other peers, while not making corrections to your own.
Had to do some more work arounds for swinging a sword too.

But when I started working on projectiles, I started running into more problems which ended up with me creating projectile dummies for the peer and disabling projectiles that were synced back from the host.
I thought that there must be some easier way to do this, and so I thought about it for a while and realized it would be much easier if the sync objects function could be toggled to sync to specific peers instead of all of them, all the time.

So my question is, is there an easier way for a peer to create a sprite, continuously relay the sprite's data to the host, and then have the host sync it back to all peers instead of the one that created the sprite?

That would basically fix a lot of my problems with how multiplayer is handled.
B
13
S
2
Posts: 33
Reputation: 883

Post » Wed Jun 08, 2016 11:44 am

I doubt that there will be any changes made to the multiplayer plugin for now or in the future.
However I also had to deal with issues like that and I found a workaround for it which Ashley does not recommend to use.
Simply get the coordinates or any information you need and sync it up as chat/text, how you fetch the information is up to you.

Again it is not recommended to use this method since the object sync is more optimized for lag prediction and so on,
only use it if your game really requires it. (Mostly games which require precise movement profit from this workaround.)
ImageImageImage
B
64
S
24
G
78
Posts: 666
Reputation: 45,070

Post » Wed Jun 08, 2016 12:27 pm

multiplayer plugin is full of bugs > dont use it
instead use websocket + nodejs
B
16
S
6
Posts: 243
Reputation: 1,755

Post » Wed Jun 08, 2016 2:03 pm

I can suggest you try out the Photon Cloud plugin. Very easy to set up and get working. I'm using it for my game and it's great.
Follow my progress on Twitter
or in this thread Archer Devlog
B
41
S
18
G
19
Posts: 1,045
Reputation: 13,977

Post » Wed Jun 08, 2016 7:03 pm

@TheRealDannyyy
Yeah, I knew someone who tried to sync stuff up with the messages and that did not work out.

@mahdi71
The C2 page for websockets says definitely don't use websockets for real time games.

@tunepunk
Could you go into a little detail on how this works?
I have no idea what this is or does
B
13
S
2
Posts: 33
Reputation: 883

Post » Wed Jun 08, 2016 8:29 pm

@Fervir It's basically a cloud server that handles all the multiplayer stuff. There's no host or peer like the regular multiplayer. You connect and send data like movement, rotation, position, whatever through the cloud server to all other users in the same room. The user can create their own private rooms on demand, or join random rooms. I think each room can handle up to 16 players at the same time. That's basics of it.

Check out this thread https://www.scirra.com/forum/plugin-photon-cloud_t125222 or read some more at the http://www.photonengine.com
Follow my progress on Twitter
or in this thread Archer Devlog
B
41
S
18
G
19
Posts: 1,045
Reputation: 13,977

Post » Mon Jul 25, 2016 7:26 pm

@tunepunk

Do you know how to get the Photon plugin to work with Pathfinding?

Ive got a TD based game and all is working well, but i cant seem to get the Objects (enemies created ) to be in sync with the other players.

I looked at the platform demo, but no luck.

Would i need to raise a event for each object created? what if im spawning 100?

Would love it if you could steer me in a direction. Thanks
B
11
S
5
Posts: 14
Reputation: 957

Post » Mon Jul 25, 2016 9:23 pm

Projectiles are difficult to code with the MP plugin because of the delay in creating and destroying objects.

The workaround I've used is to sync an INVISIBLE authoritative projectile via the host, and have create a visible sprite on the peer side for local input prediction. When the invisible host projectile gets synced, the local visible projectile will smoothly correct its position. On the host side, the "true" projectile will spawn a little farther forward with lag compensation, and peers can do similarly with reverse lag compensation

This works best for slow moving projectiles. The difference in speed/angles upon spawning and catching up to the authoritative marker should be difficult to notice if done well.

Basically, this is a recreation of the lag compensation and local input prediction systems for movement already baked into the MP plugin, except for the purpose of creating and destroying objects.

For faster moving projectiles, this may not be ideal and it may just be best to show peers delayed, synced objects. This issue is not unique to the multiplayer plugin and is more an issue with netcode in general - you'll have to deal with the lag somehow in the end.

If you don't care about an authoritative host, then you can just ignore the sync functionality all together, and have each peers update each other with messages. It will work as you described - the host will receive a message from the peer, and can relay a message to all peers with the contents and maybe a tag to identify which peer it comes from. This doesn't solve the lag issues though, which you'll still need to account for.
Mistakes were made.
B
53
S
27
G
114
Posts: 1,699
Reputation: 64,446

Post » Tue Jul 26, 2016 7:54 am

@cliffordwh Pathfinding I'm not exactly sure what you could do with. I havn't looked in to that. But you should be able to just sync the start and end positions. But only have 1 actor trigger. You can check the lowest actorNr to be sort of the Host, that handles all the pathfinding, the rest of the users, don't calculate paths, otherwize there will be conflicts probably.

If you want to create 100 objects. Send with the event the ammount to be spawned as well. For example 100, then. Then when the actors recieve the event.

Repeat (Photon.PhotonData) times. - > Create objectSprite

The best is to send the content of an array through photon as JSON. Then you can send a lot of stuff in 1 event. Check the Photon examples, (I think it's the fish tank) there's example of how they do that.

Using this way you can send X, Y Rotation, Speed, whatever you want in one single event, just populate the array with everything you need to send at 1 time.

If you're spawning something randomly, make sure only one of the actors triggers the event, then send all the random positions through photon to the other actors. If all actors calculate random positions they will all have different random positions. (Not synced)
Follow my progress on Twitter
or in this thread Archer Devlog
B
41
S
18
G
19
Posts: 1,045
Reputation: 13,977

Post » Tue Jul 26, 2016 9:43 am

@tunepunk, thanks for the logic on that. Makes sense what you saying. Yes i am making use of the Array example which is great!

Thanks again, will give it a bash
B
11
S
5
Posts: 14
Reputation: 957

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 8 guests