Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants