Handling Latency/Dead reckoning

I’ve managed to incorporate Photon Cloud into one of my apps, and it works. However I need a way to handle mobile latency.

At the moment I’m only updating one player position for testing. The Photon Cloud server I’m connecting to has an average 30ms ping, and I’m estimating that I have a lag of about 200-300ms from the time an event is dispatched (x,y coordinates only) to the time that the player has changed position on the remote device. I’m assuming this lag is down to mobile latency.

Are there any libraries (LUA or otherwise) that can help in handling dead reckoning / cubic splines to minimize the effects of Internet lag?

Ingemar,

 Have you had any luck figuring this out? I have just finished reading all the DOCs and sample code and I feel I have my head wrapped around the process. I plan on adding this code to a game I have been working on.  I was using the LUASOCKETS lib to send peer to peer messages using UDP , but I was only able to get it to work on a local wifi network. I couldn’t get the NAT Hole punching thing to work.  When Photon was added as a plug-in I knew my solution was near. The latency you bring up might cause some issues as my game is played in real-time and timing is an issue. 

 It was my understanding the photon server is only used for matchmaking/lobby and all messages to and from players was sent directly using UDP. If that is the case I can’t see any faster way to send the messages.  I see from the demo code that the service was refreshing every 100 ms  

timer.performWithDelay( 100, function() view.game:service1() end, 0)

 Could that be lowered to say 10?

Chris

No I haven’t been able to tackle the lag issue yet.

The docs state that you should call the service() function around 10-50 times per second. I’ve played with different settings and the overall lag is about the same. You should be careful not to send too many events in a short timeframe as the buffer overflows when it reaches 100 unhanded events. 

The concept of this type of game is a bit different since there is no server in the middle handling the game logic. Instead, one of the devices will have to become the master which performs all physics calculations and then sends position data of objects to the remote device. I say this since I don’t trust that physics can be assumed to behave exactly the same on different devices (especially between Android<->iOS).

The concept works, however I need to be able figure out how to handle and disguise the lag.

Any pointers would be greatly appreciated…

Ingemar,

 Have you had any luck figuring this out? I have just finished reading all the DOCs and sample code and I feel I have my head wrapped around the process. I plan on adding this code to a game I have been working on.  I was using the LUASOCKETS lib to send peer to peer messages using UDP , but I was only able to get it to work on a local wifi network. I couldn’t get the NAT Hole punching thing to work.  When Photon was added as a plug-in I knew my solution was near. The latency you bring up might cause some issues as my game is played in real-time and timing is an issue. 

 It was my understanding the photon server is only used for matchmaking/lobby and all messages to and from players was sent directly using UDP. If that is the case I can’t see any faster way to send the messages.  I see from the demo code that the service was refreshing every 100 ms  

timer.performWithDelay( 100, function() view.game:service1() end, 0)

 Could that be lowered to say 10?

Chris

No I haven’t been able to tackle the lag issue yet.

The docs state that you should call the service() function around 10-50 times per second. I’ve played with different settings and the overall lag is about the same. You should be careful not to send too many events in a short timeframe as the buffer overflows when it reaches 100 unhanded events. 

The concept of this type of game is a bit different since there is no server in the middle handling the game logic. Instead, one of the devices will have to become the master which performs all physics calculations and then sends position data of objects to the remote device. I say this since I don’t trust that physics can be assumed to behave exactly the same on different devices (especially between Android<->iOS).

The concept works, however I need to be able figure out how to handle and disguise the lag.

Any pointers would be greatly appreciated…

@ingemar
Did you complete your game?  Would love to try it if yes! 
How was your experience using Photon? 

Nope. I couldn’t get around the round-trip lag issue. I admit that online multi-player gaming is not my forte, so it may just be my attempted implementation that was the problem. Nevertheless I mothballed the project for now…

Ah well… never mind then! 

I use photon for my game sailboat battle. Live action shooter multiplayer game. I don’t see too much lag from photon but there are a few things I do to smooth things out. When a boat sends their location to the other boats I do not simple update x and y, I transitionTo. This helps alot. There ate still times where lag gets too much, but I watch for that and disconnect anyone who is seeing too much lag. If your on a slow connection you may have troubme.
My game is only out for Android now but working on the ios. If you have two android devices load the game on both so you can see how synced the boats are.
Chris
Sailboat battle arena

Thanks for the pointers @ebookren
I did try out the game a few days back, and the multiplayer part was pretty smooth…  A few glitches, nothing more… 

A few questions : 

  1. Which Photon service did you use?  Photon Turnbased, Photon Realtime or Photon Server
         (I am currently testing on Turnbased, which apparently supports realtime multplayer despite its name!_)
  2. Where do you handle your game logic? Serverside or Clientside?
  3.  It was my understanding the photon server is only used for matchmaking/lobby and all messages to and from players was sent directly using UDP
    Really? I didn’t think that was the case…looked highly unlikely… can you confirm it? 
    4.Did you use any client-side predicting to compensate for network lag?
     

I used photon reatime. All game logic and physics are handled on each person’s machine. Messages sent to players in the same room are sent directly via UDP and I do not use any server side code.  The photon server is there to set up matches/lobby.

I may have made my game different than most games because I do not have a ‘server’ , each device is a client and server. as a client the location and speed of the boat is determined by local physics and local game logic. A couple times a second I have each boat send it’s current location , direction, and speed to every other boat.  I take that data and update all boats using transitionTo as a way of making changes in direction appear to happen smooth. When a user fires their cannon I send a message to all other boats that a cannon was fired, who fired it, where did it start and where should it end.The other devices will then spawn a cannon ball with that data. Only if the cannon ball hits your boat on your local device do I send out data to the other players that my boat was hit.  There are times when it might look like you hit the other boat but the few ms difference can give them time to move out of the way. 

I do not use any predictive algorithms other than using transitionTo to smooth things over.

I do want to mention when I created the game i started with photon’s example code for Corona. In that example the photon server pointed to is one in the UK. I’m in the US. All my tests and tweeks were based on the latency of the UK server. Once I noticed this and changed over the to US server things got even better. That change has not been pushed to the Play store so the game is still using the UK server with minimal latency. 

The game can have 8 players in a game at once where player 9 creates a new game field. It is possible that with a full game of 8 the latency issues might start popping up, but I have had little opportunity to test with so many devices at once. 

Chris

@ingemar
Did you complete your game?  Would love to try it if yes! 
How was your experience using Photon? 

Nope. I couldn’t get around the round-trip lag issue. I admit that online multi-player gaming is not my forte, so it may just be my attempted implementation that was the problem. Nevertheless I mothballed the project for now…

Ah well… never mind then! 

I use photon for my game sailboat battle. Live action shooter multiplayer game. I don’t see too much lag from photon but there are a few things I do to smooth things out. When a boat sends their location to the other boats I do not simple update x and y, I transitionTo. This helps alot. There ate still times where lag gets too much, but I watch for that and disconnect anyone who is seeing too much lag. If your on a slow connection you may have troubme.
My game is only out for Android now but working on the ios. If you have two android devices load the game on both so you can see how synced the boats are.
Chris
Sailboat battle arena

Thanks for the pointers @ebookren
I did try out the game a few days back, and the multiplayer part was pretty smooth…  A few glitches, nothing more… 

A few questions : 

  1. Which Photon service did you use?  Photon Turnbased, Photon Realtime or Photon Server
         (I am currently testing on Turnbased, which apparently supports realtime multplayer despite its name!_)
  2. Where do you handle your game logic? Serverside or Clientside?
  3.  It was my understanding the photon server is only used for matchmaking/lobby and all messages to and from players was sent directly using UDP
    Really? I didn’t think that was the case…looked highly unlikely… can you confirm it? 
    4.Did you use any client-side predicting to compensate for network lag?
     

I used photon reatime. All game logic and physics are handled on each person’s machine. Messages sent to players in the same room are sent directly via UDP and I do not use any server side code.  The photon server is there to set up matches/lobby.

I may have made my game different than most games because I do not have a ‘server’ , each device is a client and server. as a client the location and speed of the boat is determined by local physics and local game logic. A couple times a second I have each boat send it’s current location , direction, and speed to every other boat.  I take that data and update all boats using transitionTo as a way of making changes in direction appear to happen smooth. When a user fires their cannon I send a message to all other boats that a cannon was fired, who fired it, where did it start and where should it end.The other devices will then spawn a cannon ball with that data. Only if the cannon ball hits your boat on your local device do I send out data to the other players that my boat was hit.  There are times when it might look like you hit the other boat but the few ms difference can give them time to move out of the way. 

I do not use any predictive algorithms other than using transitionTo to smooth things over.

I do want to mention when I created the game i started with photon’s example code for Corona. In that example the photon server pointed to is one in the UK. I’m in the US. All my tests and tweeks were based on the latency of the UK server. Once I noticed this and changed over the to US server things got even better. That change has not been pushed to the Play store so the game is still using the UK server with minimal latency. 

The game can have 8 players in a game at once where player 9 creates a new game field. It is possible that with a full game of 8 the latency issues might start popping up, but I have had little opportunity to test with so many devices at once. 

Chris