I've read several articles published on gambrielgambetta.com, gafferongames.com plus some pages about how Valve handles multiplayer networking in its games but I still can't get it how to implement the client-side prediction for my game where the player's always moving and he controls the speed by pressing the spacebar. When the client input has arrived the server already had simulated the world using the old velocity values. So we get a stretch in time.
Let's imagine that the player is moving between the 0.0 and 1.0 values. The current position is 0.2. The normal speed is 0.1. The "crawling" speed is 0.05.
Let's assume the server and the client have framerates both fixed and the latency is two steps high.
STEP 0
server 0.2
client 0.2STEP 1
server 0.3 (+0.1)
client 0.3 (+0.1)STEP 2
server 0.4 (+0.1)
client 0.4 (+0.1)STEP 3 (Spacebar's pressed)
server 0.5 (+0.1)
client 0.45 (+0.05)STEP 4 (Spacebar's still pressed)
server 0.6 (+0.1)
client 0.5 (+0.05)STEP 5 (Spacebar's still pressed. Finally, the input has arrived)
server 0.65 (+0.05)
client 0.55 (+0.05)STEP 6 (Spacebar's still pressed)
server 0.7 (+0.05)
client 0.6 (+0.05)STEP 7 (Spacebar's released. Input was sent)
server 0.7 (+0.05)
client 0.7 (+0.1)STEP 8
server 0.75 (+0.05)
client 0.8 (+0.1)STEP 9 (Input has arrived)
server 0.85 (+0.1)
client 0.9 (+0.1)
It looks like nothing's wrong with this data while every multiplayer game's trying to hide the latency. But what if the periods of pressing the spacebar are different and the latency is different and the server and client have different framerates. I can't use the input duration when updating the player position because it allows the player to cheat (just lower the duration and you will start moving slower). And the server reconciliation works not very good since I'm getting the effects derived in the statistics above. When pressing the spacebar the player just jumps back and starts moving slower. So I need to compensate that somehow.
The core of the problem is how to handle the player input when the user can only decrease the speed of the character while the character's moving with the predefined speed.