Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: bizilux on November 05, 2013, 06:57:34 PM

Title: PHOTON synchronizing problem. Cars are lagging alot.
Post by: bizilux on November 05, 2013, 06:57:34 PM
hey guys...

so i've been fooling around with photon for couple of hours, trying to make this work... and i finally pulled it off, but the problem is that it looks laggy, and out of synchronization and basically not smooth...

basically its a racing game, so there will be cars, so i have 2 instances opened, and 2 cars there... just watch the video and look for urself that it is not smooth...

Not a valid vimeo URL
oh and im using edy's vehicle physics asset, and FSM's that i have on car are basically copy-paste of "Fsm Photon player" that comes with DemoWorker example. i've just removed animation FSM, because i dont have any anymations...
(http://i.imgur.com/YmNKB1f.jpg)


you can see that physics of collisions are really f*cked up... in singleplayer if i have 2 cars they collide like they should, and basically if you ram one car against second car, the second car will get pushed away, etc... but when in multiplayer, this isnt the case as you can see...

is it because edy's vehicle physics asset? or am i doing something wrong


one thing to note: at 0:25, when i go out of the game and in again, you can see player count is at 3 somehow, but i only had 2 instances opened... you think theres problem here?
its the same at 1:08 when i respawn another instance
Title: Re: PHOTON synchronizing problem. Cars are lagging alot.
Post by: jess84 on November 05, 2013, 07:08:33 PM
With regards to the juddering, it might be the same problem that I encountered:
http://hutonggames.com/playmakerforum/index.php?topic=5126

To narrow it down, I basically assigned a Player # via a global bool, and then on each Character (1-4) on the controls FSM I put in a check for the Player # global bool and only allowed the correct player to control each character.

You might want to throw in something like that temporarily to see if it's the control from the other player's instance that's causing the judder.

My experience with Photon was an absolute nightmare, it took far longer so get things working initially than I imagined, and even when changing tiny things it tends to fall apart.
Title: Re: PHOTON synchronizing problem. Cars are lagging alot.
Post by: bizilux on November 05, 2013, 07:36:27 PM
yes... it might be the problem with somehow not disabling all control scripts...

basically im in bit of a pickle... because this edy's vehicle physics is huge... and contains lots of scripts, i think im gonna have to ask owner for help here... 
its not like the demo where you just disable character controller and thats it :(


the thing is, when i play singpleplayer, controls are 100% disabled if i want them to be...
basically there is 1 boolean in "car control" script called, "Read User Input" and if its off, in singleplayer that car remains totally still and not receiving any inputs from keys... so im just really surprised that it could be this... because it just works in singleplayer


i dont really understand how you solved that problem, ur saying you assigned Player ID to players? but then you say you did it with global boolean? thats true/false?


photon is been a nightmare for me too... its got really high learning curve, its complex stuff... but yeh thats to be expected for multiplayer... multiplayer after-all is a rocket science to write from scratch.
Title: Re: PHOTON synchronizing problem. Cars are lagging alot.
Post by: jess84 on November 05, 2013, 07:45:21 PM
Yep, I created 4 buttons on my front end menu screen - P1-P4, and when clicked, they set a global bool - e.g. "Player1" = True. Then after setting up the room and loading into it, on the Player 1 Character gameobject's Player Control FSM, I added a 'bool test' state at the top (so it's tested from the Start transition) to check for Player 1 = True.  If that's true, then allow the rest of the controls to be used.

And the same for the Player 2 menu button / Character gameobject / controls FSM.

It basically ensured that ONLY the one and correct player could control each character. In theory it should have been possible with the 'ismine' stuff on the Photon FSMs, but it just didn't work - I'd always get other players affecting each other slightly, which created the juddering.

Edit: Oh, and to make that work, I duplicated my player character so I had 4 seperate ones (rather than instantiating from the same game object), but that makes sense later anyway as I'll be having 4 visually different characters with different abilities.
Title: Re: PHOTON synchronizing problem. Cars are lagging alot.
Post by: bizilux on November 05, 2013, 08:19:55 PM
Quote
Edit: Oh, and to make that work, I duplicated my player character so I had 4 seperate ones (rather than instantiating from the same game object), but that makes sense later anyway as I'll be having 4 visually different characters with different abilities.

ye i was thinking about that last part... because your system wouldnt work with Photon Instantiate action that im using right now...

i'll try to do that and we will see if it will work...

oh 1 more question: did you remove all FSM's on players? you only had photon view and proxy on player?  or did you just remove behavior FSM and let position sync FSM and rotation sync FSM and variable sync repository FSM in there?
Title: Re: PHOTON synchronizing problem. Cars are lagging alot.
Post by: jess84 on November 05, 2013, 08:29:22 PM
As I said, it wouldn't be ideal long term, but it might help you identify the problem.  (It wouldn't take long to temporarily modify your Photon Network Instantiate target)


These are the ones I have left, and everything works for me. (I basically copied most from the DemoWorker character and modified as needed)

Animation Sync
GameObject Naming
Position Sync
Rotation Sync
Variable Sync Repository
Photon Network Sync
My controls FsM
Playmaker Photon Game Object Proxy
PhotonView
Title: Re: PHOTON synchronizing problem. Cars are lagging alot.
Post by: bizilux on November 05, 2013, 08:45:27 PM
Quote
As I said, it wouldn't be ideal long term, but it might help you identify the problem.  (It wouldn't take long to temporarily modify your Photon Network Instantiate target)

oh yes thats not a problem, i will just place 2 cars in scene instead of using initiate action... i was just wondering if you did it in that way

oh 1 more stupid question :)

i noticed you have Photon Network Sync there... i know this is auto created if you use photon setup wizard. but what do you have in that FSM?

i thought Variable Sync Repository from DemoWorker example, is just a renamed FSM for Photon Network Sync... is that not the case? :/
Title: Re: PHOTON synchronizing problem. Cars are lagging alot.
Post by: jess84 on November 05, 2013, 09:05:15 PM
I think it is. The Photon Network Sync FSM on mine is empty. I should probably delete it, but I've found that deleting even the most deletable things has unexpected consequences  :)
Title: Re: PHOTON synchronizing problem. Cars are lagging alot.
Post by: bizilux on November 05, 2013, 10:16:06 PM
well i tried it... photon doesnt like me at all...

just feeling delightful when the core mechanics of the game is not working...  game will only be multiplayer and i cant figure that photon thing... ah what a bummer...

basically i've put 2 buttons in game, and 2 cars in game, 1 button enables "Read User Input" for first car, and second button enables it on second car...

the thing is when i open 2 instances everything is ok, and when i click on button 1 to control car 1, on that instance it is ok, but on the second instance it is still choppy when turning...  going in a straight line kind of works OK, with a bit of delay on second instance... but turning, aka rotating... that has huge choppiness to it... :/

and when i click on button 2 on second instance... then things really go all weird with glitching and stuff, the car just wont move and it just sort of freezes in that place, going back and forth a bit...

i dont know... i guess i'll try tomorrow with "Fsm Photon player" from demoworker example, instead of cars... and see how that turns out... but yeh i think that will work just fine, its something to do with cars... so complicating :/
Title: Re: PHOTON synchronizing problem. Cars are lagging alot.
Post by: jeanfabre on November 06, 2013, 12:57:22 AM
Hi,

 Yes, start with a simple "player" dummy to make sure your photon routines are working.

 I think you are facing two issues, photon setup and multi player physics games... I think you should ask for guidance on the Photon forum on how to set up a a physics bases racing game, I am not sure myself how to achieve a decent multi player physics dependant world, it might require a proper server running a headless Unity version of your game that centralize all inputs and compute the physics only here, making all other running instances slaved.

but there might be a simpler approach.

Bye,

 Jean
Title: Re: PHOTON synchronizing problem. Cars are lagging alot.
Post by: bizilux on November 06, 2013, 11:48:21 AM
well im in deep shit when even Jean doesnt know how to solve this issue... and you are Photon God, compared to me :) im just little Peasant who picks up potatoes and carrots on his little farm lol :D

i tested it with demoworker prefabs and its working... so yeh i'll try asking on photon forum and report back here...

and also... i made "work in progress" thread here, you can play current singleplayer version
http://hutonggames.com/playmakerforum/index.php?topic=5404.0
Title: Re: PHOTON synchronizing problem. Cars are lagging alot.
Post by: jeanfabre on November 08, 2013, 01:59:27 AM
Hi,

 you should definitly gather as much info and consulting on this from various places, it's been done before, so it must be feasible, but at what cost in terms of server knowledge and expertize, that's the catch...


bye,

 Jean
Title: Re: PHOTON synchronizing problem. Cars are lagging alot.
Post by: drakuls on December 02, 2013, 04:15:55 AM
Hi!
I am also developing game with Photon. I have a question did you managed to get the wheels to stear and spin - so the other players can see other drivers car wheels stearing and spinning ?

Thanks!
Title: Re: PHOTON synchronizing problem. Cars are lagging alot.
Post by: jeanfabre on December 02, 2013, 04:51:28 AM
Hi,

 To do this, you need a two stage synchronization, at least this is how I would experiment with this:

-- synchronize user input, so that you control the wheel collider exactly the same
-- synchronize gameobject position, so that you avoid drifting of the gameobject real location because of the user input synchronization latency.

 the other way to do this, is to have fakes wheels on the slaved instance that matches the wheels from the master, then you don't need to control the wheel collider per say, but simply visually show it with just the wheel mesh.

bye,

 Jean
Title: Re: PHOTON synchronizing problem. Cars are lagging alot.
Post by: bizilux on December 02, 2013, 11:46:20 AM
hey guys, a small update...

we are now a team of 5 people, and we actually switched to uLink library... its much better than photon, when it comes to physics... because photon is just not made for such things...
Title: Re: PHOTON synchronizing problem. Cars are lagging alot.
Post by: jeanfabre on December 02, 2013, 11:59:43 AM
Hi,

 Keep us updated!

Bye,

 Jean
Title: Re: PHOTON synchronizing problem. Cars are lagging alot.
Post by: drakuls on December 02, 2013, 01:46:16 PM
hey guys, a small update...

we are now a team of 5 people, and we actually switched to uLink library... its much better than photon, when it comes to physics... because photon is just not made for such things...

Hi!
We are 2 guys developing car racing game (designer and programmer).
Can you please describe in more detail what is the worst sides of photon ? Why uLink ?
Title: Re: PHOTON synchronizing problem. Cars are lagging alot.
Post by: bizilux on December 02, 2013, 02:24:43 PM
hey guys, a small update...

we are now a team of 5 people, and we actually switched to uLink library... its much better than photon, when it comes to physics... because photon is just not made for such things...

Hi!
We are 2 guys developing car racing game (designer and programmer).
Can you please describe in more detail what is the worst sides of photon ? Why uLink ?

photon is mainly meant for games that are not using physics, as far as i've seen... you would need to write ur own physics library/engine...

uLink allows us to make seamless MMO,   (seamless MMO is world of warcraft for example), and it uses unity physics engine and it has lots of premade code already written for it... for example we are using smooth rigidbody improved script, that basically predicts with help of interpolate and extrapolate, where the car will be at certain time, until player and other clients get new update from server...  this helps with ping and lag a bit...

and ofcourse we are using authoritative server. so all physics are handled on server, and player only sends commands to server, for example: im holding down forward arrow, and then server does its calculations, and sends state back to player, and all other clients, the position of car based on pressed forward arrow...

price is more expensive, but if you think price/time... it would take us a lot of time, to get proton to the level that uLink is...

photon is good for small games that dont use physics, but for something like racing game, i think its a no-go...

have you actually made anything in photon? are synhronizations working? i mean is multiplayer working and cars drive nicely?
Title: Re: PHOTON synchronizing problem. Cars are lagging alot.
Post by: drakuls on December 02, 2013, 03:12:01 PM
hey guys, a small update...

we are now a team of 5 people, and we actually switched to uLink library... its much better than photon, when it comes to physics... because photon is just not made for such things...

Hi!
We are 2 guys developing car racing game (designer and programmer).
Can you please describe in more detail what is the worst sides of photon ? Why uLink ?

photon is mainly meant for games that are not using physics, as far as i've seen... you would need to write ur own physics library/engine...

uLink allows us to make seamless MMO,   (seamless MMO is world of warcraft for example), and it uses unity physics engine and it has lots of premade code already written for it... for example we are using smooth rigidbody improved script, that basically predicts with help of interpolate and extrapolate, where the car will be at certain time, until player and other clients get new update from server...  this helps with ping and lag a bit...

and ofcourse we are using authoritative server. so all physics are handled on server, and player only sends commands to server, for example: im holding down forward arrow, and then server does its calculations, and sends state back to player, and all other clients, the position of car based on pressed forward arrow...

price is more expensive, but if you think price/time... it would take us a lot of time, to get proton to the level that uLink is...

photon is good for small games that dont use physics, but for something like racing game, i think its a no-go...

have you actually made anything in photon? are synhronizations working? i mean is multiplayer working and cars drive nicely?


Yes in our case the multiplayer is working. Basically everything works smooth and in sync, just using .lerp functions between the received frames.
For more secure multiplay I even managed to adapt interpolation and extrapolation scripts- so i can change parameters and adjust the moment when the lag starts to happen and when car is realistically moving. I havent tried with more than two cars yet- maybe then the problems starts to happen :). Basicaly now I have one final problem, that the player cant see other players cars wheels spinning and steering. You know. Just like photon says - Iam using in Resources folder my cars prefab. Prefab has its own PhotonView, with OnPhotonSerializeView stream script. This Car Prefab also contains wheels and other stuff. And I even tried to attach another photonview to the each wheel and created OnPhotonSeriealizeView streams for them.. But nothing changes... Tried many different combinations, I just dont understand what is the problem.

Basicaly I am now thinking to try uLinks Trial version and adapt it to my game. And than see what changes what not.
Title: Re: PHOTON synchronizing problem. Cars are lagging alot.
Post by: bizilux on December 02, 2013, 03:32:27 PM
oh well i couldnt get it to work... and then i decided to get team and do it with uLink... so yeh i was alone when trying to get photon to work with it...

one thing you could try is, not send any wheel information over network, but have each client rotate wheels along their pivots based on how fast the car is going... it wont be peerfect and it will need quite a bit of tweaking to get it right probably... but yeh its something... and for front 2 steering wheels, its a bit more complicated... you could rotate them towards where the car is heading... but i can imagine this wont work that well at all...

but im sure there is some way to do it over photon... if you managed to do everything else... rotating the wheels shouldnt be that big of a problem? :)

but yeh photon can be a bitch some times...
Title: Re: PHOTON synchronizing problem. Cars are lagging alot.
Post by: jeanfabre on December 04, 2013, 05:34:43 AM
Hi,

you will face this problem with all netwrking solution, I don't think photon is to blame here ( unless another networking solution has some drag and drop systems for physics stuff).

 Also, I heard that Unity networking has a special physics networking view, maybe you shoudl investigate this as well.

bye,

 Jean