.

Cyborg Netcode Overview

Unity project template to get 2D online multiplayer games up and running quickly, with the full server stack included so you can host anywhere you want.

If you've attempted to make your own netcode and found it daunting or frustrating, ran into jitter, looked at other solutions and found them expensive then this project is here to help!

Out of the box features we got:

  • Client side prediction
  • Deterministic 2D physics and Cross Platform Play
  • Entity interpolation
  • Ghost manager
  • Client-server model with master server
  • Client Hot Joining
  • NAT punchthrough
  • Linux compilation ready
  • Plus a working example with PVP and PVE baked in

Read the full features list below for more indepth information

COMING SOON

Codes cleaned up, just need to get the documentation sorted out and we're ready to roll!

About the Project

Under the hood, this project relies on LiteNetLib for UDP networking with reliability built in as needed, and SoftFloat which helps keep the physics predictable. The rest of the networking engine was cobbled together by me, a sort of engine(mine) within an engine(Unity).

Originally this started as a theory into practice project, but looking around Unity's networking options and how expensive some of them were, figured I'd flesh it out so I could make myself a full game.

I was hoping to build a Udemy course to build the project from scratch with students, but the code base has gotten bigger then intended so now it will release as a project template to get people up and running quick.

During covid times, I've relied on online games to bridge the gap of my social life and this has been true for quite a few people. So the more online games the better!

Live Demo

You can play the example live here. Jump on and fight other players or the monsters in the world to try it out.

Theres enough of a game to try all of the main features, without me having to spend ages on adding juice and polish to it haha

Features!

With a lot prebuilt for users, I'm hoping devs can just get stuck right into developing their core gameplay and mechanics straight away.

Client Side Prediction

When the user presses a button, we want to see that reflected immediately similar to a one player game. Client side prediction runs your players inputs locally, then when a snapshot comes from the server we can adjust things using a rollback process that makes sure the server is still the authority. This is done without any jitter or jerky movements, except in the extreme cases of players being hit hard and fast off course by other players. In such an event, things are corrected and the player is back client side predicting accurately again.

Deterministic 2D physics and Cross Platform Play

Having deterministic physics means we avoid jitter on client side prediction, but also its been done in a way to allow cross platform play.

Unity uses Box2D which does not achieve the above well, so this project has a simple 2D AABB physics system written from scratch using the SoftFloat library.

Floats in code are great, except each different cpu architecture decides how to deal with rounding on the trail end, which can screw up determinism between platforms, especially on physics and animation. By using SoftFloat, the maths is done in software in a predictable way

Entity Interpolation

Client side prediction covers the current player, but everything else a player views around them, such as other players, items, monsters etc, then thats covered with entity interpolation. Fancy words, in short; positions of other things in the world are lerped between their last 2 snapshots from the server, to create smooth movement without any jarring jumps

Ghost Manager

If your game has a lot of players or networked things in the world, too many to fit their snapshot data into a single packet, ghost manager helps here. It collects data of all the closest world entities to each player to send them unique snapshot data of relevant parts of the world to them.

This means you can cram your world with things and it wont break the packet size. Being limited on entities would be quite annoying. This will take care of that for you automatically.

Client-Server Model with Master Server

Some networked solutions don't let you control the server tech, which means you are locked into requiring their existance to continue your game community and likely paying to keep it alive. This project gives you all of it, so you can host it anywhere you want. No reliance on anyone specific and even handy if you plan to give it to your community later in the cycle so they can keep the legacy going

Out of the box you get a master server, which is used to keep track of clients and servers and helps them connect.

The game server code is written in such a way that you run them as dedicated servers or as peer hosted servers, where the server can also be a player. Dedicated is good for big community or deathmatch types of games, where as the peer hosted approach is great for letting players host their own co-op experience to play with friends

Client Hot Joining

At the moment the current engine is only sending sync packets. This data is information relevant to around the current player. Since its all the data needed, then new players joining part way through a game will be able to join relatively quickly. As soon as the next sync packet is in, they'll be up to date with the server.

NAT Punchthrough

With the master server running, you can use it to help servers and clients connect. Part of this process is using NAT punchthrough, which helps connections happen without the need for port forwarding on the server and client sides. As long as the master server is hosted in a way where its portforwarded, then it can help others connect without the hassle

Linux Compilation Ready

Out of the box this works great on Windows, but its been tested and tweaked to run well on Linux too. Server hosting is a great deal cheaper if you run a Linux instance, which is what I do on Linode for about $5 amonth. On that $5 instance I can run about 20+ servers of the sample project and get 30 odd players joining on each.

Plus a working example with PVP and PVE baked in

The project has a first to 10 kills top down deathmatch mode in place, with some random monsters on the field to show how AI/PVE stuff could work too. You could take this starting point and take it in many directions

Games You Could Make With This :D

These are some sample ideas, but as long as you're thinking 2d you can probably pull it off. Even a 3d game that relies on the 2d physics would work too.

Deathmatch or Battle Royale

The demo shows you can make a deathmatch and the ghost manager means we can technically run the game with 100 or even more players.

Co-op Story

Using a similar approach to the demo, you could pretty easily make an old skool Zelda style game you can play with friends. You could even build a roguelike such as Nuclear Throne fairly easily from the starting demo project too.

Beat Em Up

Minor code tweaking to take out the 4 directions and change it to 2 and you have yourself a beat-em up you can play with friends!

Platformer

Using some solid detection code, you can work out where ground is, add some gravity and have a platformer up pretty quickly.

MMORPG

In theory you could do this. Main limitation is that the server is in the scene that it is in charge of. So if you went 1 scene big open world with a cap on player numbers at some threshold you could or if you got creative and worked out how to have multiple game servers running, managing different scenes of the world. You could do it.

Games Not Suitable >:O

If you're thinking of making games like these, maybe check in with another product that will help more and save you time. I want to do more features, but not all will fit under this projects umbrella

Fighting Game

You want Rollback Netcode for fighting games to be sweet. I want to implement that at some point for fun, but it wont be in this project as its a specific setup. If you make a fighting game with my netcode, I don't feel it will live up to the standards of what fighters want. Look into GGPO perhaps

Shooting Deathmatch with Hit-Scan Weapons

Shooting games with insta hit weapons have an approach coded in called Lag Compensation to compensate for simulations being likely slightly off per client. I have not gone down this path, but I would like to add it to this project at some point... In the meantime check something else out

Physics Game

The physics in this project is very simple. Its custom built. IF you want to add to the physics engine built here to cater for other shapes, then go for it, but otherwise it'll likely save you time finding a product that helps on this front

Fully 3D movement

I only have 2d physics built into this thing at this stage sorry. So if you need physics to move in 3 dimensions, maybe look into Unreal Engine or if you can afford the server costs, Photon