4

I'm programming a server for my game and cannot figure out how to mantain the movement speed. Depending on what's running on the computer, the movement is either very fast or very slow. I've already tried to make my own delta methods for the server, but it won't work. I cannot use the Slick delta variable on update since the server is programmed using AWT & Kryonet.

Does anyone know how to maintain movement?

Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151
niccholaspage
  • 41
  • 1
  • 6
  • 1
    Do you have some concept of time in-game? Perhaps events all happen at specific times, and even if your server doesn't get around to handling the event for 200ms, it doesn't change when the event happened "inside" the game... – sarnold May 29 '12 at 00:42
  • 3
    Can you expand on: *"but it won't work"* ? – Greg Kopff May 29 '12 at 00:45
  • The client has a concept of time, but it isn't used since the movement is done through the server. I tried to make a delta update thread which updates the delta, but that failed and always returned the delta as 0. – niccholaspage May 29 '12 at 01:04
  • If you show us the `delta update` code maybe we can help you get that working, otherwise there is very little for us to go on in the question. – gingerbreadboy May 29 '12 at 12:54

1 Answers1

4

Your game server needs to have a definitive global time. I'd suggest using System.currentTimeMillis();

You'll have to base movement off of equations based on time then. Since loops on your machine won't execute at an exact rate, you need to get delta time passed by using the System.currentTimeMillis() subtracted from the previous time value. Use that value in your movement equations to get consistent looking movement. If you are calculating physics (ie movement), you'll want to use Runge Kutta order 4 equations, not the normal Euler equations (Euler compunds errors over time).

Other helpful links:

http://gafferongames.com/game-physics/integration-basics/

https://developer.valvesoftware.com/wiki/Latency_Compensating_Methods_in_Client/Server_In-game_Protocol_Design_and_Optimization

aglassman
  • 2,643
  • 1
  • 17
  • 30