From using lag simulation, I learned that the client’s time is always ahead or behind the server’s time.
As a small example, suppose the delay is 1 second.
If I ask the server for the time, it’ll tell me that the server is 60 seconds in.
If I ask the client for the client time (NetworkManager.LocalTime.Time), it’ll tell me that the server is 61 seconds in.
If I ask the client for the server time (NetworkManager.ServerTime.Time), it’ll tell me that the server is 59 seconds in.
How do I sync the client’s time, such that both the client and server say that the server is 60 seconds in?
ORIGINAL TITLE:
When casting a spell, or spawning an enemy in the future, how do you synchronize the event between players?
ORIGINAL POST:
In netcode for gameobjects, how do we make sure a future event happens to all players at the same time?
Conceptually, one of the ways to handle latency is to queue actions in the future rather than them handling immediately.
Suppose the delay is 0.5 seconds in the example, 2 examples are:
Suppose a player intends to cast a fireball client side in 2 seconds (animation/casting bar). On the server, we know it’ll be cast in 1.5 seconds (due to the 0.5 seconds latency). For other players, it’ll be cast in 1 second.
Suppose the server intends to spawn an enemy in 5 seconds. On the player side, it would spawn in 4.5 seconds due to latency.
I’ve been playing around with LocalTime and ServerTime. I can’t think of a good method that is resilient against latency and jitter. How do we typically handle this in netcode for gameobjects?