Slide 40
Slide 40 text
var correction = function(time, state, input, entity, rk4) {
...
if (Math.abs(state.x - lastMove.state.x) > 2) {
...
var currentTime = time,
currentInput = input;
entity.setState(state); // Rewind entity state
var move, // Current move
frameTime; // Time between correction and stored move
for (m = 0; m < moveCount; m++) {
move = moves[m];
frameTime = (move.time - currentTime) / 1000;
// Update physics based on corrected time, input and state
...
currentTime = move.time;
currentInput = move.input;
move.state = entity.getState();
};
};
};