Lag problem
Options
Hi,
With some friend we are creating an online game (tps) on network using Photon + Unity3D and we got some problem.
To deal with move we make like this:
1. A client Ask the server if he can move by sending an operation (OpCustom) with h & v (move vector)
2. If the client is allowed to move the server Broadcast an event move to all player in the room including the asker.
3. The client catch the event and make the object move.
Everything work (chat/target/move) execpt that we have a lot of lag while moving. (client run around 70fps && ping is around 10/50ms)
Anyone got some issue like this ? I can add more précision if you need. Some told me to reduce fps in the client but it doesn't seems to work. (got some problem to specify fps max in unity).
Is there somethings that we forgot on client or server side ?
Thanks -)
With some friend we are creating an online game (tps) on network using Photon + Unity3D and we got some problem.
To deal with move we make like this:
1. A client Ask the server if he can move by sending an operation (OpCustom) with h & v (move vector)
2. If the client is allowed to move the server Broadcast an event move to all player in the room including the asker.
3. The client catch the event and make the object move.
Everything work (chat/target/move) execpt that we have a lot of lag while moving. (client run around 70fps && ping is around 10/50ms)
Anyone got some issue like this ? I can add more précision if you need. Some told me to reduce fps in the client but it doesn't seems to work. (got some problem to specify fps max in unity).
Is there somethings that we forgot on client or server side ?
Thanks -)
0
Comments
-
Are you using the "Photon Unity Networking" package (classes: PhotonNetwork, PhotonView) or are you using the "regular" API?
You are hosting the server yourself, right?
The server by default uses a mechanism to aggregate commands to send to each client. This adds lag and saves bandwidth. You can reduce this lag by using the "right" SendParameters in the server. When you send an event, those are applied and you can "flush" an event if needed. See that page's bottom
http://doc.exitgames.com/v3/new%20in%20 ... /upgrading
This would be the brute force way to reduce lag: "Send Delay and Ack Delay"
http://doc.exitgames.com/v3/photonserver/setupandconfig0 -
On server side we use a custom solution inspired on the lite/liteLobby sample.
On client side we use PhotonUnity3D.dll with IPhotonPeerListener interface.
I don't think it's a bandwith problem since we're hosting and working on local with 1gbps connection. It's more a conception problem on the client side, it look like the client get too much info than he can threat. Not sure i'm clear.
We tryed to reduce fps on client is it usefull ?0 -
do you have a mechanism that reduces the rate at which it checks for incoming messages?
Cause you never should removed it from being called each update or you can get message flooding which at worst can lead to a flooded network device at which point you get all kind of strange and basically untrackable bugs and anomaly
PS: If this is a custom thing then its the wrong board. "Unity Networking Plugin" is the new 'like unity networking' photon library available on the asset store basing on Photon3 LoadBalancing0 -
I have no mechanism to reduce rate. You mean reduce rate on client or server ?
+Sorry for wrong board, if a md can move it0 -
With reduce the rate at which it checked I meant the client side. On the server side there is no explicit call to it only the configuration entry but its basically impossible to cause similar problems on that end to what 'timer checks for the Photon message processing' causes on the client end0
-
Ok ok. We'll try that. I'll keep you in touch.0
-
Hey we try it and it still doesn't work.
We just saw a problem, when we display stats in unity we're @ 40ms/frame when we're online on our world. And average 15ms Offline doing the same action.0 -
is there anything going on cpu - physics - rendering wise when online?
thats a pretty major delta and the only two things that lead to such deltas is more to render (more animated actors especially) or significantly more physics to handle or a combination0 -
It's good to know which base you work on.
Of course you could flood the client. Also sending big volumes of data adds lag to anything sent afterwards.
How much are you sending to your clients? Size of packages, frequency and maximum usage?
How are you sending movement? How often and which data?0 -
Nothing change in physics and rendering between online and offline.
We send like this:
---> everytime we have an Input on client:
peer.OpCustom((byte)NetProto.MOVE, new Hashtable {{(byte)100, 0.0f}, {(byte)101, v}, {(byte)102, h},{(float)103, Time.timeSinceLevelLoad}}, true, (byte)1);
----> The server catch it and send back an info message about move: [Ok/Stun /Slow]
>We catch in on client and display the message if there is one.
----> The server broadcast to all clients in the room a Hashtable to move the good object with:
in: public void EventAction(byte eventCode, System.Collections.Hashtable photonEvent) we do
Player[(int)p[(byte)100]]._moveController.SynchronysePosition((float)p[(byte)105], (float)p[(byte)106], (float)p[(byte)107]); //Replace the player if position is not the same as the one on server.
Player[(int)p[(byte)100]]._moveController.BasicMoveAction((float)p[(byte)102], (float)p[(byte)103], (float)p[(byte)104]); //Make the move
The code is not that dirty i just simplified it to make concept easier to read.
Thanks for your support0 -
it's one input per frame but the problem is when we sends packets :
actuali the network works like this:
client request 1
client request 2
client request 3
client request 4
then:
server response 1 + broadcast move to other clients
server response 2 + broadcast move to other clients
server response 3 + broadcast move to other clients
server response 4 + broadcast move to other clients
the problem is how to synchronise clients and server because at that time we didn't fix the fps and a client wich have more fps is smoother than others and send more move than others so others clients are lagging.
for the moment network is faster than display sometimes we are up to 25/30ms to render a frame.
At this time we are wondering if we should implement something like this:
http://developer.valvesoftware.com/wiki ... Networking
or if similar features are already in the photon lib.
PS: sorry for my bad english0 -
yes you definitely need to send input ticked or it will flood the network and worse than that present you with plentitudes of inputs which lose any meaning.
also why are you broadcasting the input? that makes no sense. if you use input then you have an authorative environment which means you wouldn't broadcast it but only send it ot the simulation node / master client / whatever you call it. the one node doing the simulation.
if the system isn't authorative then you would send position and rotation, velocity and angular velocity as you need them to interpolate and extrapolate (unity networking example covers all those points. while being for unity it shows you the technics in question)0 -
Where can we find a sample that show us the rigth thing to do with unity.0
-
at this time we want to do an authoritative server and only for moves we send position and rotation to the server.
we don't know how to move players on serverside because we didn't know how to know the map on serverside (we didnt know how to parse unity assets ie: the map).0 -
Unity Networking Example can be found in the resources - example section at the Unity Page.
Its for Unity Networking naturally but basically but its really simple to understand if you have basic knowledge in networking (the Unity networking, as limited as it is in functionality, also gives you relative clean code to understand )
As for your problem with the map: well if you want collision or simulation on the server there are 2 ways:
1. Roll all yourself into photon and also the unity clients, not using unitys physx at all
2. Use Photon Unity Networking or a similar approach where you have a 'Master Client' that acts as simualtion node within your game and which is unity based. This node would then be the one getting the input, do the simulation and sent out positions, rotations and velocities. With Photon Unity Networking that would already all be doen for you basing on the LoadBalancing project, if you created an own solution it can be a bit trickier but doable too (PUN is based on Lite, though a pretty massive expansion ), you just need to think about how to identify the simulation node etc.
Our current project uses PUN and we have 3 types of clients basically, not just client and master client, but a third one, a Dashboard (unity editor extension listening to the stuff happening in the game). I handle that by having the regular clients RPC a specific function upon connect and having the master client keep track of it so the respective informations get to the right nodes.0 -
Hi, first of all thank you all for your answers.
We think we have found the problem. it look like the creation of the Hashtable we need to send to opCustom is very slow. That explain the freeze. I read something about the replacement of Hashtable by Dictionnary in the photon 3 RC. Do you think it will solve our problem to migrate from photon 2 to photon 3 ?
Is this the reason you change from hashtable to Dictionnary ?
Thanks. :ugeek:0 -
The reason for switch of hashtable to Dictionary is just that its more efficient and less code. With hashtables you had to do a lot of force type casting to get the same efficiency on the data handling as the dictionary in the RC3+ give you.
But the data creation will not change, it just takes its time to create data for sending and again time to serialize it. Question is if you can cache it to just 'update it' in the future for example. That holds for the code you have as well as Photon 3 code for example
Unsure to what degree Photon 2 -> Photon 3 would change anything in such a case or if your problem is really there at all0 -
Hell !0