• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

Clientside prediction & correction

5 posts in this topic


I'm creating a 2d sidescroller mmorpg and I wanted to ask how to program client-side prediction & correction?
Well especially the correction, because prediction is basically just running the physics code you have running on the server.
The server sends corrections about every two seconds. This messages contains X & Y positions and X & Y velocity and the Input like
left 0, right 1, jump 1...

Is it ok that I do the same for other clients? So instead of sending snapshots of position and velocity, I only send input that has changed, and the local
client will predict where the other clients are moving to. The server sends corrections every 2-3 seconds.

Thanks a lot!

Share this post

Link to post
Share on other sites

Sending commands are much more efficient than sending snapshots of position.
The client should be able to calculate and run the command such as "moveto objectid,x,y,speed".
Sending corrections... I do not get it... The coordinate system should be the same everywhere.
A little difference is acceptable.

Share this post

Link to post
Share on other sites
Here's a simple way to do it:

My assumption is, that the server outrules everything else, that is, the only consistent world exist on the server side. The client controls the own player and predicts the other players.

You could use two steps (client side):

1. step:

Prediction is done only on the client side. For each player you got the following data
t = time
x,y = position
vx,vy = velocity

That is, you need to hold the last X frames of data you receive from the server (history of server-side player movement)

t_0 is the current time. At this time the current player position is not available by the client yet, so you need to predict it. A simple prediction would be to extrapolate the position/velocity on a spline depending on t_4,t_3,t_2,t_1. To refine it, you can use this extrapolated data as input for your physics engine , to predict a more consistent position/velocity.

t_0 is always recalculated , whenever you receive a new data tuple, you need to update your history of t_4 to t_1 accordingly.

Step 2:
The problem is, if positioning the player directly at the position at t_0, and you receiving new data (=correction), then you get choppy movement. To avoid this, you need to approximate the calculated position in a smooth way. That is, instead of just positioning the player on the calculated position at time t_0 you take the current position and target position (t_0) and interpolate the position to the target position on a smooth curve.

Share this post

Link to post
Share on other sites
In the quake series of games the prediction and correction is done like this:

each command has a timecode.
Clients run their user commands locally in realtime. this is your prediction. The client also saves state of the result of each movement command and the timecode for that command/state pair.
Client sends bunches of commands including previous commands over udp at a regular interval.. the reason for duplicaitng older commands is to compensate for packet loss.
Server rebuilds the user command stream using the timecodes.

Server simulates all usercommands that have a newer timecode than the user command executed last frame on the server.
At each snapshot, the server sends back the state of the last executed command and the timecode of that command. We can call this the "Last Acknowledged Command" (LAC).

When the client receives the snapshot, the client character is immediately snapped to the state that the server snapshot indicates. The client then uses the timecode of the snapshot as a start point and simulates all the user commands locally that occur after the snapshot to bring the client back into realtime predicted state. This is done within one frame and any huge error will be smoothed over the next few frames. The result is that if the physics sim is deterministic, the client and server will agree most of the time and you will not see much snapping at all.

Even without error smoothing I've had a 200ms connection feel smooth.

They also use delta compression on the bunches of commands and snapshots to minimize bandwidth usage.

Also to note is that on the server, each client is in a quasi stable state. The snapshots takes stills of this and the clients tend to interpolate remote players between snapshot orientations or actually accept a list of commands to sim the remote player characters. The result is that all remote players look smoothish to each client, but if you were local to the server, using the server's direct state, you'd see every remote player jittering.
This is why the local client on a listen server in id games is an actual client that also recieves snapshots from the server code and does all processing in duplicate of the server (for it's own client character at least) as a real client should.

This method also requires that each character can be simulated through physics separately from the rest of the world. This will not work with globally correct physics sims that aim to sim the entire world each frame (your character running into a stack of cardboard boxes). Some intermediate might be possible where if the client impacts objects that can move, that those objects are now brought along into the independant simulation of the client commands that have reached the server. Edited by Infernal-rk

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0