Playmaker Forum

Playmaker Help & Tips => Playmaker Help => Topic started by: Krillan87 on December 26, 2017, 10:01:01 AM

Title: Sync moving scene objects in Photon?[SOLVED]
Post by: Krillan87 on December 26, 2017, 10:01:01 AM
Hi,

So I have a made a multiplayer game that has some moving parts locally in the scene. The moving parts are stuff that has a constant speed and the players can't interfere with them. Like elevators etc.

So I wanted to save some network data and instead of syncing every moving little object I just checked when both players are connected and then restarted the scene for both players, making the game "start at the exact same time" and making all objects sync locally.

However, there is some latency in photon anyway so it was not a perfect sync. Is there a better way of syncing stuff like this?

Is it possible to check the ping in the start and then correct the starting time accordingly?

What is the best way to go about syncing stuff that the players can't interact/interfere with? (Like in a co-op game you want the players game to start at the same time.)

/Christian
Title: Re: Sync moving scene objects in Photon?
Post by: Krillan87 on December 29, 2017, 02:17:59 AM
Anyone?
Title: Re: Sync moving scene objects in Photon?
Post by: 600 on December 29, 2017, 05:56:25 AM
Hello, maybe use RPC to set start movement.
Another idea, the host set Server Custom property, like bool and all players check it.
Title: Re: Sync moving scene objects in Photon?
Post by: Krillan87 on December 29, 2017, 06:22:49 AM
Hello, maybe use RPC to set start movement.
Another idea, the host set Server Custom property, like bool and all players check it.

Hi!

Thanks for you input. I feel like the RPC way is to heavy for just syncing the start.

Care to elaborate what you mean by sing Server Custom Property for this?

Bye,
Christian
Title: Re: Sync moving scene objects in Photon?
Post by: 600 on December 29, 2017, 06:37:57 AM
The RPC is not heavy at all, if not EveryFrame, same for Properties, sent only once similar as Global Event the movement processed locally on player’s side.

Photon will update values in Room properties, actions:
Set Room Custom Property
Get Room Property

The difference would be, with RPC the elevator would be ordered to move, but with Properties the elevator would check when to move.
Title: Re: Sync moving scene objects in Photon?
Post by: Krillan87 on December 29, 2017, 11:01:33 AM
The RPC is not heavy at all, if not EveryFrame, same for Properties, sent only once similar as Global Event the movement processed locally on player’s side.

Photon will update values in Room properties, actions:
Set Room Custom Property
Get Room Property

The difference would be, with RPC the elevator would be ordered to move, but with Properties the elevator would check when to move.

Alright, I should look into the properties.

I was a bit unclear what I meant with the RPC being heavy. It feels like its a lot more work, because then I need a FSM on every moving object in the whole scene.

It feels like if I only can get both all connected computers to restart the level at the exact same time, all the moving objects will be sync automatically which feels like the best and easiest way.
Title: Re: Sync moving scene objects in Photon?
Post by: Krillan87 on January 02, 2018, 03:50:29 AM
Does anyone know what is the best practice here? I really feel that the best way to go about is to try to restart the level for all players at the exact same time, and everything will be synced automatically.

Anyone with insight of how "real studios" do this?
Title: Re: Sync moving scene objects in Photon?
Post by: 600 on January 02, 2018, 04:09:13 AM
Not sure about "real studios", the restart on each pc would be in different speed/time, so you could only have some kind of wait system, that host wait until all players are loaded. With same RPC message for example.
But still it is not so reliable if you sync only the needed moving parts in demand.
Title: Re: Sync moving scene objects in Photon?
Post by: Krillan87 on January 03, 2018, 02:14:14 AM
Hi again!

Thank you for your time an patience. I do not want to sound ungrateful for you help, I really appreciate it, and you sure got more experience then me in this area but I fail to understand how your tip would help here.

If something would start the very first frame of the game, (if it is a RPC call or if it is just a both computer that's restart the scene) it all comes down to how fast the computers load right?

I feel I can't really wrap my head around this, fairly simple, issue.

I have not worked with room properties before, so maybe the answer lies there?
Title: Re: Sync moving scene objects in Photon?
Post by: 600 on January 03, 2018, 04:05:35 AM
Sure no problem, I can speak only of what I have seen/used.
So in multiplayer if you want the closest sync with Photon cloud, then use everyframe variable synch. Other than that not sure if there are any more precise measures, except Authoring server setup which is different setup, like all is calculated on server machine and all users get the same behaviour on synched entities. This is not included in Photon cloud and the implementation is different. I have not worked with it.

About the difference of things I mentioned. Basically as you say it is the same - level restart or RPC.
But if only sync the level restart, the difference with pc and network ping will only match once - at start. but if you use RPC or check for room properties, the example elevator would have more sync checkpoints. Sending RPC on movement start and movement end can speed up or wait for other player’s elevator to match its position. Some delay there will be anyway.
Title: Re: Sync moving scene objects in Photon?
Post by: Krillan87 on January 03, 2018, 04:32:29 AM
Sure no problem, I can speak only of what I have seen/used.
So in multiplayer if you want the closest sync with Photon cloud, then use everyframe variable synch. Other than that not sure if there are any more precise measures, except Authoring server setup which is different setup, like all is calculated on server machine and all users get the same behaviour on synched entities. This is not included in Photon cloud and the implementation is different. I have not worked with it.

About the difference of things I mentioned. Basically as you say it is the same - level restart or RPC.
But if only sync the level restart, the difference with pc and network ping will only match once - at start. but if you use RPC or check for room properties, the example elevator would have more sync checkpoints. Sending RPC on movement start and movement end can speed up or wait for other player’s elevator to match its position. Some delay there will be anyway.

Alright I see. I feel like the best way is to use a RPC call some how.  I'm not sure how to do this practically speaking.

So the elevator should stand still in the start and receive a RPC call to begin moving when both players are loaded? Or how should I go on about to fix this? How do I secure that the RPC call fires of in the right moment?
Title: Re: Sync moving scene objects in Photon?
Post by: 600 on January 03, 2018, 04:50:23 AM
I see it as my traffic lights, every X seconds an RPC is called to everybody switch lights. Could do something similar.
Can have maybe two events or one event with value like 0 or 1.
Host sends 0 - everyone update their elevators at ground floor, if 1 then drive up and stay there. With value in RPC you can even show a number of floor if there are more.
Title: Re: Sync moving scene objects in Photon?
Post by: Krillan87 on January 03, 2018, 05:40:53 AM
I see it as my traffic lights, every X seconds an RPC is called to everybody switch lights. Could do something similar.
Can have maybe two events or one event with value like 0 or 1.
Host sends 0 - everyone update their elevators at ground floor, if 1 then drive up and stay there. With value in RPC you can even show a number of floor if there are more.

Hmm.. okey. Maybe I forgot to mention that the elevators cant be interacted with. They just move up and down in a constant speed. I really really feel like there must be a easier way to just make them start at the same frame.

I saw that there is a "Photon transform view" component. It kinda feels like that is something I need? Does the other photon components work?
Title: Re: Sync moving scene objects in Photon?
Post by: jeanfabre on January 05, 2018, 04:10:12 AM
Hi,

 There will always be latency, it's inherent to the network architecture and data transfer speed of the internet.

The most direct and performant way is to fire an RPC when the elevator starts. The latency can be counter indeed by using the server timestamp and do some math to move the elevator where it should be based on the difference between your time and the server time. But really, I doubt this is worth the effort.

 Can you describe why this affect your gameplay? maybe there is a better way to tackle this?

Also, have you checked TrueSync: https://www.photonengine.com/en-US/TrueSync

 it provided a determinist and 100% accurate simulation of the game on all players, if you are affected by latency so badly, maybe this is worth checking out ( reuqired coding, PlayMaker can not work with TrueSync because of the different way to store numbers)

 Bye,

 Jean
 
Title: Re: Sync moving scene objects in Photon?
Post by: Krillan87 on January 08, 2018, 02:46:17 AM
Hi,

 There will always be latency, it's inherent to the network architecture and data transfer speed of the internet.

The most direct and performant way is to fire an RPC when the elevator starts. The latency can be counter indeed by using the server timestamp and do some math to move the elevator where it should be based on the difference between your time and the server time. But really, I doubt this is worth the effort.

 Can you describe why this affect your gameplay? maybe there is a better way to tackle this?

Also, have you checked TrueSync: https://www.photonengine.com/en-US/TrueSync

 it provided a determinist and 100% accurate simulation of the game on all players, if you are affected by latency so badly, maybe this is worth checking out ( reuqired coding, PlayMaker can not work with TrueSync because of the different way to store numbers)

 Bye,

 Jean

Hi Jean!

I understand that there will always be some latency, but when I check the ping I got with Photon is around 40-50 and the "latency" is way above that, so I get the feeling it is no a latency issue but a issue of how my RPC/FSM are set up. There must be something else that cause the latency.

It does no affect my gameplay a whole lot in this game particularly but I want to understand why this happens so in future game I can correct it.

Okey so now I tried the RPC to fire of the elevator. (I've included a picture of the FSM). Basically the FSM just checks for how many connected players there are and if it is equal to the max player the game restarts and after the restart if the game is full it will not restart again but instead start the elevators (RPC Start game sends a RPC to start all the elevators on the scene)

Here is a video of the result:
https://ChristianE.tinytake.com/sf/MjI0OTg4M182OTQxNzEx

The first issue here is that the elevator on the right is not synced with the one on the left.

There is also a position issue with the player. I guess this comes from the lerp of the positionen? I there a good way of fixing this?

Is all this something that I just have to accept? Maybe there is impossible to get a more synced game?

/ Christian
Title: Re: Sync moving scene objects in Photon?
Post by: jeanfabre on January 09, 2018, 04:15:22 AM
Hi,

- one way to solve this is is to send an RPC to everyone and elevator only responds to the rpc call as opposed to start running on the client that initate the call and have all other clients waiting for the rpc to do so, the initiator should also wait for the rpc, then it's totally fair for everyone.

- the other solution is to use the server time stamp in the rpc and deduce the current position based on this

- another solution is to make the elevator a network gameobject that belongs to the scene ( to the madterClient), and you symchronize the position without PlayMaker at all, you simply use the component PhotonTransformView shipped with Photon itself)

 Let me know how this goes.

 Bye,

 Jean
Title: Re: Sync moving scene objects in Photon?
Post by: Krillan87 on January 10, 2018, 03:13:36 AM
Hi,

- one way to solve this is is to send an RPC to everyone and elevator only responds to the rpc call as opposed to start running on the client that initate the call and have all other clients waiting for the rpc to do so, the initiator should also wait for the rpc, then it's totally fair for everyone.

- the other solution is to use the server time stamp in the rpc and deduce the current position based on this

- another solution is to make the elevator a network gameobject that belongs to the scene ( to the madterClient), and you symchronize the position without PlayMaker at all, you simply use the component PhotonTransformView shipped with Photon itself)

 Let me know how this goes.

 Bye,

 Jean

Hi and thank you for your answers, Jean. I have some follow-up questions regarding your 3 solutions:

- one way to solve this is is to send an RPC to everyone and elevator only responds to the rpc call as opposed to start running on the client that initate the call and have all other clients waiting for the rpc to do so, the initiator should also wait for the rpc, then it's totally fair for everyone.

+ How do I do this? I thought that it exactly this the the RPC call did. I have included a picture of the RPC call and from my understanding the client that initate the call has to wait for the call to return via the "game manager" that is a scene object in the scene.

- the other solution is to use the server time stamp in the rpc and deduce the current position based on this

+This solution sounds a bit to hard an complicated and i think its above my competence. Is this the best way, performance wise, to fix the issue?

- another solution is to make the elevator a network gameobject that belongs to the scene ( to the madterClient), and you symchronize the position without PlayMaker at all, you simply use the component PhotonTransformView shipped with Photon itself)

+ This solution founds very easy to use. I still had some issues where the movement got a bit jerky. I guess that's because photon sync the positionen all the time. I guess this is the easiest solution but use pretty high network data?

What is the pros and cons with the different solutions? What take would you recommend?

/Christian
Title: Re: Sync moving scene objects in Photon?
Post by: Krillan87 on January 10, 2018, 03:23:01 AM
Hi,

- one way to solve this is is to send an RPC to everyone and elevator only responds to the rpc call as opposed to start running on the client that initate the call and have all other clients waiting for the rpc to do so, the initiator should also wait for the rpc, then it's totally fair for everyone.

 Bye,

 Jean

Okey I think I found this one. In Photon Targets I should choose "All via server" instead of "all"? I found this on the photon forum:

The difference between AllViaServer and All target is the path that the RPC takes for the local player.
With "All", PUN sends the RPC to the others and executes it locally. This saves the roundtrip and some traffic but the execution order is different locally than for everyone else.
With "AllViaServer", PUN asks the server to send the RPC to everyone, including "this" client. PUN does not use a shortcut and execution of the RPC is in the same order as on other clients.


Is that correct?
Title: Re: Sync moving scene objects in Photon?
Post by: jeanfabre on January 10, 2018, 10:09:12 PM
Hi,

 If this is in the doc, it's likely correct. I would double check and make sure it's case and move on if that's suitable for you indeed.

 Bye,

 Jean
Title: Re: Sync moving scene objects in Photon?
Post by: Krillan87 on January 11, 2018, 02:04:34 AM
Hi,

 If this is in the doc, it's likely correct. I would double check and make sure it's case and move on if that's suitable for you indeed.

 Bye,

 Jean

Okey so you gonna double check and write back to me? I an mostly interested in the RPC-solution but there is very little information on the RPC-actions in playmaker and what they do. Like for instance the "RPC Target".

Is there any more detailed documentation on the RPC-actions btw?
Title: Re: Sync moving scene objects in Photon?
Post by: jeanfabre on January 12, 2018, 12:16:54 AM
Hi,

 I mean "If I were you, I would double check" :) Sorry, bad english...

to kearn about RPC, you need to first get acquainted with the photon doc on RPC:

https://doc.photonengine.com/en-us/pun/current/gameplay/rpcsandraiseevent

it also explains what PhotonTarget Means. but I myself got tripped with this few times when I started, the wording is fine but it may resonate differently in different developers mind, so really, it's a matter to experimenting and gaining experience with it.

The demo provided for PlayMaker Photon bridge lets you experiment with the phton target, when you use the chat feature, you can choose to whom or to what target you want to send a chat, so you can figure it out very easily this way( you don't need to write anything to test, that's what I mean)

 Bye,

 Jean
Title: Re: Sync moving scene objects in Photon?
Post by: Krillan87 on January 15, 2018, 04:12:06 AM
Hi,

 I mean "If I were you, I would double check" :) Sorry, bad english...

to kearn about RPC, you need to first get acquainted with the photon doc on RPC:

https://doc.photonengine.com/en-us/pun/current/gameplay/rpcsandraiseevent

it also explains what PhotonTarget Means. but I myself got tripped with this few times when I started, the wording is fine but it may resonate differently in different developers mind, so really, it's a matter to experimenting and gaining experience with it.

The demo provided for PlayMaker Photon bridge lets you experiment with the phton target, when you use the chat feature, you can choose to whom or to what target you want to send a chat, so you can figure it out very easily this way( you don't need to write anything to test, that's what I mean)

 Bye,

 Jean

Hello Jean,

I'v done some reading and testing. Saw that you answered some similar questions on the photon forums as well!

So Right now I just just use the fransform view that comes with Photon and it works fantastic. I have 2 questions regarding this if you wanna help.

1) Why don't I just use this "transform view" all the time in all situations? IT seems super easy to use and works very well? For instance: Instead of syncing the position values like the demo worker, why don't I just put a "transform view" on the player and observer that component? What are the cons of thos?

2) The player position while they are on the elevator are very messed up. Is this because of the lerp on both the elevator and the player? Is there a good way to fix this?

As seen in the screencast:
https://ChristianE.tinytake.com/sf/MjI2OTE2Ml82OTg1OTE0

Thank you so much for your patience and help!

/ Christian
Title: Re: Sync moving scene objects in Photon?
Post by: jeanfabre on January 16, 2018, 12:33:20 AM
Hi,

1: yes, PhotonTransformView is a very effective way, but I wanted to show what PlayMaker could do, and is actuall based on the photon demo itself which was doing it like that. That's all. Of course using PhotonTransformView is a lot quicker to setup and more powerful because it gives you all the lerping options, etc etc, so yes go for PhotonTransformView whenever Possible

2: you need to first implement a proper Platform behavior for your Player, which is not easy, then you add the network context on top. When your player is on a platform, then you have a race condition between the synch of the platform and the player, you need to account for this, and maybe ignore the y value of the player sync while on a platform, provided is not jumping... so not an easy thing to achieve by any means. and here PhotonTransformView may be getting in the way because you will have more difficulty to control exactly when and what to sync given this context.

So long story short, you need to find tricks... your Player logic when on a platform or elevator need to be aware of it and stabilize the y value. a Quick trick could be to reset the y position on late Update for your player to be on that platform. and if jumps can occur, detect when the user jumps and do not enforce this floor contact while jumping.

 Bye,

 Jean
Title: Re: Sync moving scene objects in Photon?
Post by: Krillan87 on January 17, 2018, 04:45:55 AM
Hi,

1: yes, PhotonTransformView is a very effective way, but I wanted to show what PlayMaker could do, and is actuall based on the photon demo itself which was doing it like that. That's all. Of course using PhotonTransformView is a lot quicker to setup and more powerful because it gives you all the lerping options, etc etc, so yes go for PhotonTransformView whenever Possible

2: you need to first implement a proper Platform behavior for your Player, which is not easy, then you add the network context on top. When your player is on a platform, then you have a race condition between the synch of the platform and the player, you need to account for this, and maybe ignore the y value of the player sync while on a platform, provided is not jumping... so not an easy thing to achieve by any means. and here PhotonTransformView may be getting in the way because you will have more difficulty to control exactly when and what to sync given this context.

So long story short, you need to find tricks... your Player logic when on a platform or elevator need to be aware of it and stabilize the y value. a Quick trick could be to reset the y position on late Update for your player to be on that platform. and if jumps can occur, detect when the user jumps and do not enforce this floor contact while jumping.

 Bye,

 Jean

Hello again!

Thank you so much for your valuable insights, Jean, it's really helping me alot!

I just wanna share that I now, thanks to you, made it all work! I made a trigger on the moving platform that fires off a event on the triggering character and force it Y-value to be the same as the elevator.
And a second FSM with a "on trigger exit" to go back to the regular movement.

So everything works now but I do not know if this is the cleanest and most effective way it doing it (playmaker wise) but it works. I posted to pictures as well if you were interesting.

Thanks for all help!

/Christian
Title: Re: Sync moving scene objects in Photon?
Post by: jeanfabre on January 18, 2018, 11:14:13 PM
Hi,

 good :)

 I would try not use SendEventByName and instead use a regular SendEvent, but that's minor. The rest looks fine.

 Bye,

 Jean
Title: Re: Sync moving scene objects in Photon?
Post by: Krillan87 on January 19, 2018, 02:26:26 AM
Hi,

 good :)

 I would try not use SendEventByName and instead use a regular SendEvent, but that's minor. The rest looks fine.

 Bye,

 Jean

The reason why I choose send event by name is that Send event must be to a global event, no?

I just want the regular event that is on the state to fire off so it can only happen if the the character is not local/no controllable.

Is that no correct? Can I use Send event the same way?
Title: Re: Sync moving scene objects in Photon?[SOLVED]
Post by: jeanfabre on January 21, 2018, 11:51:52 PM
Hi,

 ok, that make sense then :)

 Bye,

 Jean