playMaker

Author Topic: Sync moving scene objects in Photon?[SOLVED]  (Read 15993 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sync moving scene objects in Photon?
« Reply #15 on: January 09, 2018, 06: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

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Re: Sync moving scene objects in Photon?
« Reply #16 on: January 10, 2018, 05: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
« Last Edit: January 10, 2018, 05:15:15 AM by Krillan87 »

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Re: Sync moving scene objects in Photon?
« Reply #17 on: January 10, 2018, 05: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?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sync moving scene objects in Photon?
« Reply #18 on: January 11, 2018, 12:09:12 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

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Re: Sync moving scene objects in Photon?
« Reply #19 on: January 11, 2018, 04: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?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sync moving scene objects in Photon?
« Reply #20 on: January 12, 2018, 02: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

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Re: Sync moving scene objects in Photon?
« Reply #21 on: January 15, 2018, 06: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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sync moving scene objects in Photon?
« Reply #22 on: January 16, 2018, 02: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

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Re: Sync moving scene objects in Photon?
« Reply #23 on: January 17, 2018, 06: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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sync moving scene objects in Photon?
« Reply #24 on: January 19, 2018, 01:14:13 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

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Re: Sync moving scene objects in Photon?
« Reply #25 on: January 19, 2018, 04: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?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sync moving scene objects in Photon?[SOLVED]
« Reply #26 on: January 22, 2018, 01:51:52 AM »
Hi,

 ok, that make sense then :)

 Bye,

 Jean