Giter Club home page Giter Club logo

authoritativemovementexample's Introduction

Forge Networking Remastered Authoritative Movement Example

Created using:

  • Unity 2017.2.0f3 (uses 2017.2.5f1 as of 09/19/2019)
  • Forge Networking Remastered - Github build

What is this?

An implementation of Authoritative Server Movement in Forge Networking Remastered.

The example shows client-side prediction, reconciliation of inputs, error interpolation, and server-side authoritative processing (the server has the final say on game state).

How to use it?

Clone the project and open it in Unity. Import the latest Github version of Forge Networking Remastered (this project uses this commit). NOTE: when you import Forge Networking Remastered do NOT import "Assets/Beaded Man Studios Inc/Generated" or you will nuke the generated network object implementations!

If needed, add the prefabs of the network objects (GameManager, InputListener, Player) to the NetworkManager prefab.

Build and run two or more instances of the build (ensure the two scenes are Forge's MultiplayerMenu.unity and this example's AuthoritativeMovementExample.unity).

Host on one instance and then join on the others and you can move on any client that didn't host using the Arrow keys.

Functional Overview

This project is a very similar implementation to g-klein's AuthoritativeMovementDemo.

The main difference is how reconciliation is done in that an RPC is not used to send the game states processed on the server to the client. Instead the unreliable network object fields are used. Since missing one or two server updates isn't a big deal, RPCs aren't needed.

Also, some optimizations were done in both the Player and InputListener for reconciliation and when/how Inputs should be sent/processed.

Additionally, this build is deterministic. and Physics2D (not sure about 3D, untested) rigid body physics work as far as I've tested so far. I've changed the build to decouple Unity's Physics2D. The build now uses a very simple collision detection & resolution system using the Collider2D.OverlapCollider and Collider2D.Distance methods and direct updating of the rigidbody's position. I did this so I could simulate physics on individual objects allowing all inputs in the queue to be processed at once server side.

(Outdated - will do more testing soon.) This build was tested by me both locally (to/from localhost) and with a server hosted on a Linux VPS with ~100ms ping from my location. Clumsy Lagswitch was used to do further network testing (especially for higher pings).

Changelog

July 13, 2018:

  • Added error interpolation for movement to smooth away errors due to networked collision between players if both players are moving.
  • Fixed some bugs (namely the spawning issue which was caused by using the playerConnected event instead of the playerAccepted event for spawning).
  • Refactored code.

Resources

g-klein's AuthoritativeMovementDemo

Gabriel Gambetta

Gaffer On Games'

Source Multiplayer Networking

Fast Paced Multiplayer Implementation: Smooth Server Reconciliation

To-do

  1. Lag detection & handling - if excessive lag is detected:

    • The local client should mitigate processing time from excessive reconciliation, wait for the last processed server update and snap to there.
    • The server should stop processing inputs, extrapolate the player forward along the current movement direction until ping is either lowered (snap to position and start processing inputs again) or too high/too unstable (drop the player).
  2. Add a small time delay to incoming inputs on the server to smooth out processing processing (this may not actually be required, Forge may already do this, but I want to experiement a little time permitting).

Known Issues

  1. At high pings, non-owner clients see choppiness in the interpolation. Smoother interpolation which adapts to the ping is needed.

Disclaimer

This is a demo build and is by no means perfect. Use this at your own risk and take the time to understand how it works. Making your own improvements is encouraged and if you feel that you can contribute something back to this example feel free to contact me on the Forge Networking Discord or submit an issue.

Thanks to the members of the Forge Networking Discord who helped me extensively with ideas, discussion and feedback as I worked on this.

authoritativemovementexample's People

Contributors

relic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

authoritativemovementexample's Issues

FramesToReconcile memory leak on the server

Hiho!

Just a quick fix in the Player.cs

// movement reconcilation happens only on the local client. (client compares movements with the ones that server validated)
if(!networkObject.IsServer && _isLocalOwner) // add this "if"
    FramesToReconcile.Add(_currentInput);

The server accumulates these inputs, but it doesn't need them. It causes a huge memory leak leading to gigabytes of ram being wasted in minutes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.