0

How can I make server-side game run the same on every machine, because when I use server's delta time it works different on every computer/phone.

Would something called 'fixed timestep' help me ?

IgnasR
  • 172
  • 3
  • 10
  • Check out [Precision Time Protocol](https://en.wikipedia.org/wiki/Precision_Time_Protocol) for some ideas. – Dan Aug 16 '16 at 23:21

1 Answers1

0

Yes fixed timestep can help you. But also simple movement with a delta can help you. Fixed timestep commonly using with a physics because sometimes physics needs to be update more often (120-200hz)than game's render method.

However you can still use fixed timestep without physic. You just need to interpolate your game objects with

lerp(oldValue, newValue, accumulator / timestep);

In your case probably small frame rate differences causes unexpected results.

To avoid that you should use movement depends delta.

player.x+=5*60*delta;//I assume your game is 60 fps

Instead of

player.x+=5;

So last delta will be only difference between machines.And its negligible since delta difference between 60 and 58 fps is only ~0.0005 secs

Deniz Yılmaz
  • 1,084
  • 9
  • 16
  • I tried doing that += 5*60*delta in server and client but it happens got get desynced. – IgnasR Aug 21 '16 at 18:16
  • is server also running in 60 fps ? – Deniz Yılmaz Aug 21 '16 at 18:25
  • no it's not everything is running at n fps, I'm not limiting frames per seconds I don't know if it is a good thing to limit server fps. – IgnasR Aug 21 '16 at 18:28
  • Actually in server side games clients does nothing.server does calculations and send this data to all clients. Just send data to server and let server send your data to other devices after calculations. By the way client side game can be hacked because client side calculations can be hacked. So best way to do this is server calculation. Read here it will help you. http://gamedev.stackexchange.com/questions/20425/game-logic-on-the-server-good-or-bad – Deniz Yılmaz Aug 21 '16 at 18:34
  • but if everything is done in server and client is just displaying it then I will need to send packets every pixel that the client moves. – IgnasR Aug 21 '16 at 18:37
  • You dont have to send all data.You need only datas that will affect competition or gameplay. Effects ,random events(does not affect gameplay of course) etc can be different in all devices. However those wont affect hit point of player. – Deniz Yılmaz Aug 21 '16 at 18:41
  • I can give you and example. Big moba games like dota or lol got hundreds of little effects on map like bugs ,little animals, wave effects on water but those are not same at all devices. – Deniz Yılmaz Aug 21 '16 at 18:44
  • I thinked I made it right, your code helped, I made that when player clicks the key to move it sends packet to server and then i set velocity and it moves x+=5*60*delta and the same happens in client player moves in there and when client stops, server sends correction position for player and current position sets to the one that server sent, at the moment it works very good. – IgnasR Aug 21 '16 at 18:49
  • And also make sure that you checked that data came from server. Sometimes connection can be bad and server and client positions can be so different. Write code for limit speed if differences between positions are much greater than expected. And im happy for your success :) good day – Deniz Yılmaz Aug 21 '16 at 18:54