#Synchronizing stun / emp
10 messages · Page 1 of 1 (latest)
Can you link the guide you're referencing please
Sorry, I was referring to this https://fish-networking.gitbook.io/docs/manual/guides/lag-compensation/states
@shadow islandThat guide is kind of an alternative if you're running outside the tick system.
But to answer your question, the server sends the synchronized tick it should start on 'timemanager.Tick'.
The client receives that via obsRpc and converts it to local tick. This is because while Tick is super accurate, its still an estimate to servers current value, while LocalTick is constant/reliable
Thanks for the reply, I really appreciate it.
I understand that the guide is for running code outside the tick system, it makes sense that in the following example a de-sync will occur. ```
private uint _stunStartTick;
private uint _stunEndTick;
[Replicate]
private void RunInputs(ReplicateData data, ReplicateState state = ReplicateState.Invalid, Channel channel = Channel.Unreliable)
{
uint tick = TimeManager.LocalTick;
//do nothing if we are stunned
if(tick >= _stunStartTick && tick <= _stunEndTick)
return;
//perform movement
motor.Move();
if(IsServerStarted &&!state.IsReplayed() && ApplyStun())
ObserversApplyStun(tick + TimeManager.TimeToTicks(0.05f, TickRounding.RoundUp));
}
[ObserversRpc(RunLocally = true)]
private void ObserversApplyStun(uint serverTick)
{
_stunStartTick = TimeManager.TickToLocalTick(serverTick);
_stunEndTick = _stunStartTick + TimeManager.TimeToTicks(1f, TickRounding.RoundUp);
}```
Please correct me if i'm wrong but the issue with the above code is that the 'stun' will not occur at the same replicate tick for the server and client.
In this other example I've written up, there is no de-sync because I'm calculating the 'stun' ticks based off the replication tick that triggered it.```private uint _stunStartTick;
private uint _stunEndTick;
[Replicate]
private void RunInputs(ReplicateData data, ReplicateState state = ReplicateState.Invalid, Channel channel = Channel.Unreliable)
{
uint tick = data.GetTick();
//do nothing if we are stunned
if(tick >= _stunStartTick && tick <= _stunEndTick)
return;
//perform movement
motor.Move();
if(IsServerStarted &&!state.IsReplayed() && ApplyStun())
ObserversApplyStun(tick + TimeManager.TimeToTicks(0.05f, TickRounding.RoundUp));
}
[ObserversRpc(RunLocally = true)]
private void ObserversApplyStun(uint serverTick)
{
_stunStartTick = serverTick;
_stunEndTick = _stunStartTick + TimeManager.TimeToTicks(1f, TickRounding.RoundUp);
}```