Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having trouble understanding when to extrapolate and when to interpolate. In gaffer on games, he said to interpolate but then in another article it recommended extrapolating the player. So my question is when is it better to extrapolate and when is it better to interpolate?

share|improve this question
12  
There are two kinds of people. Those who can extrapolate from incomplete data – Almo 12 hours ago
1  
@Almo and what's the other kind? Please tell me, I must know! – DJ McMayhem 11 hours ago
1  
@DJMcMayhem ... and those who enjoy eating fish fingers. – immibis 4 hours ago

You interpolate when you know the 'before' and 'after' values.

For example: in a point-and-click game, player is currently at position X, and from his interface, he clicks on spot Y. You must interpolate the displacement between X and Y because you know the two values.

You extrapolate when you guess what's going to be future value, based on what you already know.

For example: in a first-person-shooter game, player is at position X and he's been depressing the UP arrow on his keyboard for the last second, you can suppose that he'll be doing this again for the next second because that's basically the most frequent behaviour in your game; so you extrapolate the position that he'll be next frame. The server sends it to the other game clients, this accounts for the delay in the transmission from the server to the players.

Extrapolation is used mainly for movement prediction. It is not needed by the game server, but the game clients need it to display a somewhat realistic and current vision of the state of the game in order to give a smooth visual experience to the players.

share|improve this answer
    
I understand that part but what I don't understand is when i should use each one. Like for example, if I interpolate a player, there will be a delay for him to actually see movement but if I extrapolate it will be more instantaneous but it may not be accurate and will need to be corrected. Is it usually more desirable to have the instantaneous movement from extrapolating or the more consistent movement from interpolating? – J leong yesterday
    
@Jleong You want the game presented as smooth as possible to the users. You interpolate the current state of the game, and you extrapolate how it will be in a couple of frame. You send the extrapolated values to the other players to account for the delay in the network transmission. If you were to send the interpolated values, the game would seem to lag and it would not be fun. (I edited my answer. I hope it clears it up a bit more.) – Alexandre Vaillancourt yesterday
    
oh ok so extrapolating is used when you want it the client to predict what is going to happen? If so then what is the point of interpolation if you can always extrapolate to keep the game close to real time? so for like a FPS, would the player be extrapolated and the other players be interpolated? – J leong yesterday
    
Generally, the server does everything: it interpolates on what it knows, and based on that, it extrapolates the values and send these to the clients so they arrive in time to be presented to the players. In a FPS, the interpolation is used to display things like projectiles, AI, and such. When performing Frame B (coming from Frame A) it will interpolate values for the state of Frame B; it can also start predicting Frame C by interpolation of the known values, but it will have to extrapolate values it doesn't know about (player inputs). It will then send the "future" state to the client. – Alexandre Vaillancourt yesterday

Interpolation is done when you have both a start and end value, and you want to estimate what happens between this start and end value. An example would be to move a player from Position A to Position B in a fluid motion.

Extrapolation, is done when you have a start value, but do not yet have data for the end. You can then extrapolate based on what data you have. For example, based on a player's previous movements, you can determine where he is probably going to be in the next frame.

share|improve this answer

Always interpolate when you can.

When you don't have enough information to interpolate then you need to extrapolate.

It really is that simple, don't over-think it :)

To explain a bit more:

In general interpolation is better because interpolation is always right. To extrapolate you have to guess. Then you have to deal with what happens when you guess wrong, which leads to rubber banding or popping and all sorts of systems to deal with handling all of that and disguising it.

What happens if you extrapolated a bat position and showed it going to the right place and bouncing the ball, then realize afterwards that you were wrong and it didn't bounce the ball? There is no good way to handle that scenario.

share|improve this answer
    
oh ok so in pong, the user's paddle is predicted and the ball and other paddle are interpolated? – J leong 11 hours ago
    
That entirely depends on how you implement it. See my edit for more information. – Tim B 10 hours ago

You interpolate to find states between known values, and you extrapolate to find future states.

Think of the problem in terms of state variables, like positions and velocities. In the best of all scenarios, every computer which needs to work with state has access to the state data for the time they want to work on. For example, a collision algorithm to see whether laser-rifle shot X interesets player A's head, the best of all cases is when the algorithm knows the exact position of every object at the time the laser was fired.

In the real world, we are not always so lucky. Sometimes the truth information we receive is more sparse. For example, if player A is a remote player on another computer, you may not know exactly where they're going when you fire the laser and need to calculate the shot. In this case, you need to create an estimator for A's position, typically with interpolation or extrapolation.

The difference between the two is whether you have data that is bounded on both sides, or only one side. Let's say that Player A has already announced their truth position for t=0 and t=1. Player B shoots a laser at t =0.5. In many situations Player A's announcement of their position at t=1 can occur before Player B pulls the trigger. Why? In many games, the responsiveness of the controls is less than perfectly instantaneous. In a racing simulation, much of the player's position is bounded by the physics of a moving vehicle. You may choose to announce a "future position" because you know you really can't steer all that much in a short period. If you have information in the future, you can interpolate between the two values.

What if you aren't lucky enough to have a t=1 value? What if Player A wasn't in a position to announce their future location, and you're stuck deciding whether you hit or missed with only the information from t=0? In this case you have to extrapolate. In extrapolation, you use what you know about the motion to extend beyond any data you have. You might know that Player A has a certain velocity, so presume that if you multiply that by time, you can get a position at each time.

The difference is in the behaviors. Interpolation requires you to have an upper and a lower bound, which you do not always have. However, in nearly all situations it has vastly better results than extrapolation. Extrapolation can easily lead to unrealistic movements. Consider the case of a player who is sidestepping left and right to avoid being shot while advancing. At any given point, their velocity is along a diagonal, so if you extrapolate, the player may appear to run off to the side when, in fact, they never do. If you only do interpolation, the values tend not to stray outside realistic values.

Interpolation and extrapolation are two extremes in the world of filtering. There are many many many many many filters out there for handling data like this which mix and match properties between interpolation and extrapolation. Accordingly, don't be surprised if you see algorithms that are not clearly interpolation or clearly extrapolation. Those two are just the tip of the ice berg.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.