Advertisement

Best way to get smooth player movement?

Started by August 13, 2004 11:09 AM
6 comments, last by FLAGGR 20 years, 6 months ago
I am working on a large scaleable server but I can't seem to think of a good way to handle player movement so it doesn't look jerky(as it normally does if you just send a player position anytime the player moves). I've been told by some people that the better way may be not to send a position at all, but instead to keep player position and velocity server side and simply send a movement and direction message then have the server handle all the movement calculations and return the new position to the player. The only problem I see with that method is their will be a small lag time between the user hitting a key and the message actually registering with the server and everything being updated. Can anyone suggest a better way of doing things?
For some strange reason my login didn't work and it posted annonymously, so I'll have to post a change I found here as a different post....wut a pain..the link to the post is:

Prediction
Advertisement
Thanks Permafriend, that's about what I suspected had to be done.

Great Link as well.
i think the prediction way will be better.

thats what i am intending to do for my game, i think you may find that even with a bit of lag, the player will move to the right place, just check every now and then how close the player is to where you predicted them to be. If its only a tiny bit you could even just leave them there instead of warping them to the exact position if they were off.
Sending positions will be much less error-prone than sending movement deltas imho. Just keep track of the position where the client thinks the player is and the position the server says he is - then pull the player towards the "true" position each frame by some factor...
Fenghus,

My server does a number of checks prior to creating the final message and sending it out. If the client has responded to x number of "gamestate" updates (player and entity positions) the server will send the delta. If their ping is overly high, and there is a high number of drops, then I will send the absolute positions in this case, but in this case only. The rest of the time I use linear interpolation (DX has built in methods in the D3DX library) to move the clients to where they should be if they're off by a certain margin.

Chaos, glad you found the link useful, I'm hoping to sort through it some day and create a full tutorial on it once I've finished my game so it's good to know that there is enough information in there to get someone started on it anyways ^_^.

Permafried-
Advertisement
Permafried is right, client/server prediction is the only way to go.

If your worried about cheaters, you have to consider though, what if they, for example, have a delta z of 5 (everything else is 0) so in 10 frames if the client keeps his finger on his key, then he's moved 50 units (er, i doubt you would collect input every frame, but just pretend)

So if this user was on dialup and had a huge ping, and only the first packet saying he had a delta 5 got through, then all the clients and server would have the player at 50, great, it worked.

Now imagine a cheater that sends the delta z packet, then blocks all other motion packets from going through, and say he presses D, and get's a delta x of 5, then after 10 frames his z will be 5, and x will be 45. So he will be majorly out of synch with everyone else, and could use this to sneak up on enemies, or reach a goal (like capture the flag) without anyone seeing him.

--
--
--

Not hard to fix, and there are a few ways to do it (I prefer sanity checks, theyre hassle free) but you have to think about these things :)

This topic is closed to new replies.

Advertisement