Lockstep Engine for Unity3D on top of PUN
In a lockstep engine, game clients exchange only input values. For each tick (a lockstep frame) to be simulated locally, all input values from all clients must arrive at a particular machine.
TrueSync simplifies the development of a lockstep game by providing a simple-to-use input queue. A custom simulation loop (with callbacks), and a deterministic physics engine, so developers can concentrate on gameplay code.
Cross-Platform Deterministic Physics
TrueSync comes packed with two custom physics engines, one for 2D games and one for 3D. Both physics engines are deterministic, so they are guaranteed to keep the simulation state in sync across different machines and platforms, as long as the developer follow basic rules on how to use random numbers, avoid float variables (replace them by our FixedPoint type) and properly queue input values.
The components architecture and API of these custom physics engines were developed based on Unity's built in physics engines. Developers can easily port their games to TrueSync by replacing correspondent components and doing simple modifications to existing code.
One of the greatest advantages of a lockstep system is that the only thing needed to run a replay of a game section is the sequence of input values for all game clients. TrueSync simplifies this task by recording the complete input sequence of every gameplay section for the developer to serialize and save for later use.
To run a replay, just run the gameplay scene with the previously recorded input sequence and TrueSync takes care of everything.
Rollbacks and State Tracking
A lockstep system is great for RTS and tower defense types of games. For action filled titles such as fighting and sports games, a little extra is needed to hide network latency from players. This extra is called rollbacks.
TrueSync's rollback system protects players from inevitable internet latency by locally 'guessing' the input from the other game clients, and running the simulation before all input is received.
If an input value is guessed wrongly, TrueSync recovers the game state from a previous tick and resimulates to the current one with the correct input values. All this happens automatically without any interference from the developer. Just set how many ticks you want the system to advance the simulation with the guess-rollback engine.
Even when game objects were created or destroyed because of physics callbacks, a rollback restores the previous state correctly, as long as the developer uses the provided safe methods for such operations.
For developer created custom variables, such as health value, points, etc, TrueSync provides a state tracking mechanism that includes such variables into the observed game state that is restored when a rollbacks occurs.
Full Compatibility with PUN
TrueSync is fully compatible with PUN (Photon Unity Networking). A up-to-date version is included with every TrueSync version.
PUN is used as the underlying network system for TrueSync, so a deterministic gameplay section happens between game clients that are connected to a PUN room.
Connecting to Photon Network, creating and joining a room, managing custom Photon Servers, all work exactly like a normal PUN game. It's even possible to keep using normal PUN features such as RPCs, or have a hybrid system using TrueSync and PUN's synchronisation features at the same time.
Please refer to PUN's getting started documentation on how to register to Photon and use the sample games bundled with TrueSync to learn how to start a locksteped deterministic gameplay section.