fix; NetworkTransformUnreliable now broadcasts in LateUpdate as well (#3410) (#3421)

This commit is contained in:
mischa 2023-03-28 04:59:26 +02:00 committed by GitHub
parent 527dda561a
commit ae50522895
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,13 +37,29 @@ public class NetworkTransform : NetworkTransformBase
double lastServerSendTime; double lastServerSendTime;
// update ////////////////////////////////////////////////////////////// // update //////////////////////////////////////////////////////////////
// Update applies interpolation
void Update() void Update()
{
if (isServer) UpdateServerInterpolation();
// for all other clients (and for local player if !authority),
// we need to apply snapshots from the buffer.
// 'else if' because host mode shouldn't interpolate client
else if (isClient && !IsClientWithAuthority) UpdateClientInterpolation();
}
// LateUpdate broadcasts.
// movement scripts may change positions in Update.
// use LateUpdate to ensure changes are detected in the same frame.
// otherwise this may run before user update, delaying detection until next frame.
// this could cause visible jitter.
void LateUpdate()
{ {
// if server then always sync to others. // if server then always sync to others.
if (isServer) UpdateServer(); if (isServer) UpdateServerBroadcast();
// client authority, and local player (= allowed to move myself)?
// 'else if' because host mode shouldn't send anything to server. // 'else if' because host mode shouldn't send anything to server.
// it is the server. don't overwrite anything there. // it is the server. don't overwrite anything there.
else if (isClient) UpdateClient(); else if (isClient && IsClientWithAuthority) UpdateClientBroadcast();
} }
void UpdateServerBroadcast() void UpdateServerBroadcast()
@ -151,15 +167,6 @@ void UpdateServerInterpolation()
} }
} }
void UpdateServer()
{
// broadcast to all clients each 'sendInterval'
UpdateServerBroadcast();
// apply buffered snapshots IF client authority
UpdateServerInterpolation();
}
void UpdateClientBroadcast() void UpdateClientBroadcast()
{ {
// https://github.com/vis2k/Mirror/pull/2992/ // https://github.com/vis2k/Mirror/pull/2992/
@ -245,21 +252,6 @@ void UpdateClientInterpolation()
Apply(computed, to); Apply(computed, to);
} }
void UpdateClient()
{
// client authority, and local player (= allowed to move myself)?
if (IsClientWithAuthority)
{
UpdateClientBroadcast();
}
// for all other clients (and for local player if !authority),
// we need to apply snapshots from the buffer
else
{
UpdateClientInterpolation();
}
}
public override void OnSerialize(NetworkWriter writer, bool initialState) public override void OnSerialize(NetworkWriter writer, bool initialState)
{ {
// sync target component's position on spawn. // sync target component's position on spawn.