private void FixedUpdateServer() { PlayerState finalState = ServerState; UserCmd nextCmd = null; while (m_PlayerInput.NextUserCommand(out nextCmd)) { finalState = m_TargetPlayer.ProcessUserCmd(nextCmd, finalState, Time.fixedDeltaTime); } ServerStateUpdate update = new ServerStateUpdate(); update.netId = m_TargetPlayer.netId.Value; update.Origin = finalState.Origin; update.Velocity = finalState.Velocity; m_TargetPlayer.MoveShip(finalState.Origin); connectionToClient.SendByChannel( ServerStateUpdate.MessageID, update, Channels.DefaultReliable ); ServerState = finalState; }
void ClientReceiveUpdate(NetworkMessage message) { ServerStateUpdate updateMessage = message.ReadMessage <ServerStateUpdate>(); NetworkInstanceId netId = new NetworkInstanceId(updateMessage.netId); GameObject foundObj = ClientScene.FindLocalObject(netId); if (foundObj == null) { return; } if (message.conn.playerControllers[0].unetView.netId == netId) { PlayerNetworkTransform networkTransform = foundObj.GetComponent <PlayerNetworkTransform>(); //Update the player network transform from the server networkTransform.OnServerFrame( new PlayerState( updateMessage.Origin, updateMessage.Velocity ) ); } }