Weighing smoothing options

This commit is contained in:
Jeremiah Billmann
2013-06-26 21:05:46 -04:00
parent 05c909725a
commit e321a24909
2 changed files with 12 additions and 8 deletions
+2 -2
View File
@@ -7,7 +7,7 @@ options = {
onPlayerRemove: function (id),
onPing: function (data),
onUpdatePlayerPhysics: function (state, inputs),
onInterpolation: function(previousState, targetState, amount)
onInterpolation: function(currentState, previousState, targetState, amount, delta)
logging: true,
clientSidePrediction: true,
interpolation: true,
@@ -220,7 +220,7 @@ window.GarageServerIO = (function (window, socketio) {
if (options.interpolation && options.onInterpolation) {
var positions = getPositions(players[playerIdx].updates);
if (positions.previousState && positions.targetState) {
stateCallback(options.onInterpolation(positions.previousState, positions.targetState, positions.amount));
stateCallback(options.onInterpolation(players[playerIdx].updates[maxUpdate].state, positions.previousState, positions.targetState, positions.amount, 0.015));
}
else {
stateCallback(players[playerIdx].updates[maxUpdate].state);
+10 -6
View File
@@ -2,7 +2,7 @@ $(function () {
GarageServerIO.connectToGarageServer('http://garageserver_io.jbillmann.c9.io', {
logging: true,
clientSidePrediction: true,
//interpolation: true,
interpolation: true,
onUpdatePlayerPhysics: function (state, inputs) {
var i = 0;
if (!state.x && !state.y) {
@@ -22,13 +22,17 @@ $(function () {
}
return state;
},
onInterpolation: function (previousState, targetState, amount) {
var newState = {};
onInterpolation: function (currentState, previousState, targetState, amount, delta) {
var interpolationState = {},
smoothState = {};
newState.x = (previousState.x + amount * (targetState.x - previousState.x));
newState.y = (previousState.y + amount * (targetState.y - previousState.y));
interpolationState.x = (previousState.x + amount * (targetState.x - previousState.x));
interpolationState.y = (previousState.y + amount * (targetState.y - previousState.y));
smoothState.x = (currentState.x + (20 * delta) * (interpolationState.x - currentState.x));
smoothState.y = (currentState.y + (20 * delta) * (interpolationState.y - currentState.y));
return newState;
return smoothState;
}
});