playMaker

Author Topic: (photon question) How do I restrict control of a character to it's owner?  (Read 4458 times)

Swift_Illusion

  • Playmaker Newbie
  • *
  • Posts: 41
    • Midnight Tinkering
I'm having trouble with multiple characters in the scene and I believe the root cause is that
I'm in control of both of the characters, instead of a single one and receiving information from
the server on how the other player is acting. All events etc are triggered on both characters too
(for example the left click to 'attack' is being triggered by both characters).
Is there some easy trigger for this where I can enable/disable control depending on who the owner is?
I'd greatly appreciate information on this as I can't move forward at all without fixing this.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

Yes, you are on the right path.

 The demo sample provided with the photon package for playmaker has the solution for this:
https://hutonggames.fogbugz.com/default.asp?W927

Check in particular this fsm on the player prefab' FSM:
https://hutonggames.fogbugz.com/default.asp?W875

Basically, the photon network view knows if you own this instance or not, if you own it, that is if it "is mine", then the user is in control, if not, then you need to disable user controls. simply enable disable components or tell them wether they should listen and react to user inputs or not.

This doesn't stop there, when the user is in control, you will need to tell the network what's happening with it, that is the job of synched variables:
https://hutonggames.fogbugz.com/default.asp?W874

Same principle here, when it "is mine" you need to set related synched variables, and when not, you need to read them and adjust the player instance to reflect that the user is actually doing with this player ( moving, jumping, rotating, etc etc)

 Once you understand this concept and how to apply it in playmaker, you'll be fine.

 bye,

 Jean

Swift_Illusion

  • Playmaker Newbie
  • *
  • Posts: 41
    • Midnight Tinkering
Thank you very much for all of that, the documentation is written really well :),
however regrettably it doesn't answer my particular problem.

The demo illustrates how to enable/disable those scripts based on whether you own/don't own the character,
however that doesn't help at all for my situation where the controls are based on events like the mouse
click mentioned, and simple-move (which uses the controls in project settings).

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

Yes, you will need to extrapolate this concept of ownership and apply it to fit your case. You have everything here to know when you should give control to the user or not, then of course the detail of the implementation is unique to each game really.

 Could you share your player prefab as a package, that will allow me to find a solution. Right now, not too sure I can provide any more useful directives as it really depends on what you are doing and your player is set up.

Pm me or share it on this thread if you are allowed, and I'll happily look at it.

 Bye,

 Jean

Swift_Illusion

  • Playmaker Newbie
  • *
  • Posts: 41
    • Midnight Tinkering
Thank you very much :), I realized after your last response that I did need to fit it to my case.
Instead of trying to copy the solution that worked for them, adapt it to mine. What I needed to do was instead of what they had done-trying to like how they had disabled their script, disable something in my scene- I checked at the very beginning of the FSM whether I controlled the object or not, so it never even got to check the mouse click or anything for the other character :).

So that's all working wonderfully now, and thank you very much for your help ^^,
the only last confusing part is, to get my character to synch correctly, I need to actually disable the position/rotation check and synch they have in their scene, otherwise it won't work.
That actually stops it working. For some reason they just simply synch automatically?
Is this because they used the 3rd person control script for their example, or am I missing something?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

 It's because you have your photon network view component set to watch the transform of the character in which case by default internally synch the transform. If you want to manually control this, have the network view point to the fsm component instead, like in the demo provided.

 bye,

 Jean

Swift_Illusion

  • Playmaker Newbie
  • *
  • Posts: 41
    • Midnight Tinkering
Thank you very very much :D, I knew the synch object was tracking the FSM but I'd forgotten during my
testing when I added a network view to the mesh that was actually tracking the position/rotation,
so after some adjustments it's completely working now :D!

I was wandering if you might know, whether it would be less pressure on the server to have that network
view automatically track the position/rotation, or should it be done through synch?

Also is there a particular reason rotation doesn't use a Lerp like the position. Is it just because it's not as
necessary as position to be smooth, and using Lerp would pressure the server/client speed?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

 very good.

 Rotation is not lerped because the character rotates straight, so no need. Note that lerping do not afect the server client speed, lerping is done purely on the client side, it's after the data is received, so no performance hit at all. The position lerping is the same. It's purely the mean to reproduce as close as possible the character movement, nothing pressures the server by processing the data being synched. what will pressure the server and make the multi user environment less efficient is to send to much information, so always try to keep to a bare minimum the amount of information you send ( that is the number of synched variables in your scene at a given time). Prefer RPC clla when things are granular in time, and use synched variable when they do change always ( like the character position, rotation and animation).

bye,

 Jean

Swift_Illusion

  • Playmaker Newbie
  • *
  • Posts: 41
    • Midnight Tinkering
Ahhh awesome, thank you very much for that information, and all the additional tips too :D!
And thank you again for all the previous help!, it's thanks to you I'm slowly starting to understand more
about the playmaker environment and I can move forward to develop more of the gameplay now :).
Can't thank you enough ^^