Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Introduce client side prediction and lag compensation #209

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

lionleaf
Copy link
Member

@lionleaf lionleaf commented Jan 20, 2019

I've had some fun playing around with the network code and have added client side prediction and some lag compensation :)

In addition I've changed the movement code to have instant acceleration.
Original game: http://lionleaf.org/globalgamejam2016/client/
This PR with prediction and lag compensation: http://lionleaf.org/shrinequest/client/
This PR minus the prediction and lag compensation: http://lionleaf.org/shrinequest_no_predict/client/

Changes:

  • Server now keeps a queue of input events, and iterates over all of them. The old server did not and could lose an event or two (mostly hidden by the ice-skating movement and lack of prediction)
  • Client side prediction of character position:
    • Client will keep all events sent to the server in pending_input
    • Every frame the client checks what the newest input message that was used to create the current state, and removes any input message that has already been applied by the server.
    • The character state is reset to the server state every frame and then all of the pending inputs applied to the character
    • This means the client needs access to the walls etc to predict collisions.
  • Client side predicted bullets. These are regenerated every frame based on "pending input" and are fast-forwarded the right amount of frame ticks.
  • Movement changed from acceleration based to constant increments per input message (makes it a lot easier to apply all pending inputs)

Not sure this will ever be merged, as there are a number of new bugs introduced that I'm not sure I'll spend the time to fix.

Known issues:

  • Enemy bullets spawn far from their gun. This could be fixed in a number of ways, but they all have trade-offs. You can delay the bullets, or have them spawn at the gun and catch up for instance.
  • When shooting at an enemy at close range bullets go straight through (client side predicted bullets don't collide with players)
  • Predicted bullets don't explode when colliding with a wall, they just get stuck.
  • Predicted bullets spawn when standing on Capture Points
  • Interaction with shield?
  • Dodging of incoming bullets?
  • Lag compensation does not revert game-state on server to do hit detection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant