Rollback Netcode Example

Rollback netcode is a method used to achieve seamless replication between clients in online games. One example is handling local animations. When an animation is played locally for an entity that isn’t your character, it doesn’t replicate to others. A straightforward solution is sending a remote event to all clients and waiting for each to receive it. However, this approach depends on varying client speeds, known as delayed-based netcode. To address this variability, rollback netcode comes into play.

Rollback netcode eliminates delay for the initiating client while ensuring all other clients remain synchronized. This ensures smoother gameplay experiences.

For a deeper understanding, watch this video on Why Rollback Netcode Is Better.

Example Implementation:

local Delta = (os.clock() - LastTime)
local Animation = AnimationController.LoadedAnimations[AnimationName]

if Delta > Animation.Length then
    return
end

-- Set Time Position to Match Delta
Animation:Play()
Animation.TimePosition = Delta

In this example, Delta represents the time taken for the original client to communicate with others. Adjust the animation time position accordingly, ensuring it doesn’t exceed its length.

Extreme Case Example:

In an extreme case scenario it will look a bit strange.

Here is a 500ms delay:

Rollback Netcode

Such extreme delays are unrealistic; typically, rollback netcode operates swiftly enough to be imperceptible.

This basic implementation showcases how rollback netcode can be adapted for games, including sport games like soccer or football.

For enhanced networking speed and smoother experiences, consider utilizing ByteNet by ffrostfall.

13 Likes