5

i am developing a multiplayer roleplaying game, (No, its not a mmorpg. ;)

My current setup is like this.

Client tells the server "I want to move forward"/"I want to move backwards", the server then updates your entity, and informs all clients in the area about the change. The server is also updating each entity every 20ms and sending updates every 100ms to the clients, these updates contains position, velocity, rotation etc.

So far so good, however i have nothing in store for smoothing the movement between the packets on the client side, and i must say, i can not get it working. I have been reading up on prediction, interpolation, deadreackoning but its all a big mess for me.

So right now i am just doing something like "Position = Packet.Position", which causes a very stuttering movement.

So, what i want help with is, how do i get a more smooth movement? Have been looking at the XNA Prediction Sample, but i could not get it right.

Thanks //F

Fredrik Widerberg
  • 3,068
  • 10
  • 30
  • 42
  • Do you need to make only player's movement smoother or other objects too? Do client know the player's current velocity? – ssmir Jan 18 '11 at 22:42
  • Well, currently i only have player so that is my main concern. The client knows about the velocity, it is included in the status-package from the server. Actually i got a nice answer on IRC, will try it tomorrow and if its successfull i will share. – Fredrik Widerberg Jan 18 '11 at 22:51

3 Answers3

12

Read Valve's description of their multiplayer protocol. It should be instructive, and gives a very clear example on how you do the prediction/interpolation.

I82Much
  • 26,901
  • 13
  • 88
  • 119
3

I'd suggest the idea from another question (see the accepted answer)

Here the client calculates its position itself as if its not a network game. Client regularly sends his current position to the server. And if client cheats or can't continue moving in the chosen direction, server just sends the client his correct position.

The same algorithm was used in Ultima Online (at least when I was playing it 10 years ago)

Community
  • 1
  • 1
ssmir
  • 1,522
  • 8
  • 10
  • Its funny how you mention Ultima Online, it is one of my favorite games. :) If i find issues with my current implementation i will try this. However, wont this result in quite a big difference between what player A and player B sees? – Fredrik Widerberg Jan 20 '11 at 21:34
  • @Fredrik Yep, one of my favorites too =) Actually the difference will depend on the pings of the players and can be estimated. But I don't think the difference plays any role here because e.g. when you attack someone in UO the client sends the ID of the object being attacked. So some difference in positions may be only noticeable if you put two monitors near each other and compare. Problems should start to appear when you run the game over the Internet instead of LAN. Especially if you use TCP because any packet loss results in a huge lag measured in seconds (at least). – ssmir Jan 21 '11 at 07:49
0

I solved it by running a ghost entity alongside with my main one.
The ghost will get updated every frame aswell, but whenever a packet comes in, his values are set to the values of the packet.

I then gradually tweak the real entity to where the ghost is.

Fredrik Widerberg
  • 3,068
  • 10
  • 30
  • 42