Hypothetically suppose I have a flashlight I want to activate in a multiplayer game.
Client A COULD input activate, run an activation event on the server, and then the server could use a RepNotify to set the flashlight Boolean to ON on each client.
However, this means there would be a delay (ping / pkt lag) between the player inputting the flashlight, and it actually appearing in their game.
How can I have the player activate the flashlight INSTANTLY on their game, THEN send it to the server, and then have that flashlight activate on all other clients (after the ping / pkt lag?)
i.e. client A inputs activate, flashlight is turned on for client A instantly, an RPC is sent to the server which then RepNotifies the new flashlight Boolean to ALL CLIENTS EXCEPT the player who did the activating? How do I exclude this player from acting on the RepNotify?
Why do you need to skip the action on the triggering client?
Also, a trick that’s often helpful, is to replicate “ticks of state change” rather than “state.”
In this case, you’d have two variables:
Tick number when light was last switched on
Tick number when light was last switched off
The lamp is on, if value 1 is greater than value 2.
(and it doesn’t need to be tick numbers, could be game time or whatever distributed, shared, advancing quantity your clients/server can agree on.)
Client would set “tick last switched on” to “current tick” when turning it on, and send RPC to server. Server would echo it back. When client gets the update, the value will be “set” to the same value again, idempotently.
Even if there is some glitch in transmission, the state will be eventually consistent. Lamp is on whenever “turn on tick” is later than “turn off tick,” and vice versa.