Smooth MultiPlayer movement
Asked Answered
C

3

6

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

Collinear answered 18/1, 2011 at 22:14 Comment(2)
Do you need to make only player's movement smoother or other objects too? Do client know the player's current velocity?Drinker
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.Collinear
D
4

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)

Drinker answered 18/1, 2011 at 23:6 Comment(2)
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?Collinear
@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).Drinker
N
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.

Nunley answered 18/1, 2011 at 22:20 Comment(0)
D
4

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)

Drinker answered 18/1, 2011 at 23:6 Comment(2)
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?Collinear
@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).Drinker
C
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.

Collinear answered 19/1, 2011 at 13:56 Comment(2)
so you still have a lag between the moment when the player initiates the movement and the moment when the ghost receives the new position?Drinker
Yep, however this is not noticable.Collinear

© 2022 - 2024 — McMap. All rights reserved.