Quantcast
Channel: 2D Latest Topics
Viewing all articles
Browse latest Browse all 623

My lerp function is finishing too fast, any ideas on how to fix it?

$
0
0
Im trying to make a lerp function on an online game. Im doing this by having a buffer list, I append each server update to a list, and lerp over the contents, here is an example:
 
movementBuffer.unshift(gameUpdate); //when a new update is received

//in the main loop
timeElapsed += delta;

lerpPerc = timeElapsed / updateRate; //percent which is lerped to



if(lerpPerc > 1){ //when the lerp is finished, the states that were just lerped are removed from the buffer

movementBuffer.splice(prevData.length - 2, 2); //remove the previous states from the buffer
state1 = prevData[prevData.length - 1];
state2 = prevData[prevData.length - 2];
timeElapsed = 0;
lerpPerc = 0;
}


for (i = 0; i < state2["players"].length; i++) {

// update the players
prevY = state1["playery" + state["players"][i]];
prevX = state1["playerx" + state["players"][i]];

x = state2["playerx" + state["players"][i]];
y = state2["playery" + state["players"][i]];

//lerp to the new x and y

playerCoords[recivedData["players"][i]][0] = lerpF(prevX, x, lerpPerc);
playerCoords[recivedData["players"][i]][1] = lerpF(prevY, y, lerpPerc);

}

 

 
The problem here is the `lerpPerc` goes by too quickly, so it basically deletes all items in the buffer, leaving nothing to be lerped to. What am I doing wrong here?

Viewing all articles
Browse latest Browse all 623

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>