public void OnRecv_SyncBall_Ntf(Packet.MsgSvrCli_SyncBall_Ntf ntf) { StartCoroutine(PacketDelay((float)Network.NetworkDelay / 1000, () => { GameObject go = null; if (false == this.objects.TryGetValue(ntf.ball.id, out go)) { return; } Ball ball = go.GetComponent <Ball>(); if (null == ball) { return; } ball.transform.localPosition = ntf.ball.localPosition; ball.transform.rotation = ntf.ball.rotation; ball.rigidBody.velocity = ntf.ball.velocity; if (true == GameManager.Instance.useDeadReckoning) { deltaTime += (float)Network.NetworkDelay / 1000; while (deltaTime >= Time.fixedDeltaTime) { deltaTime -= Time.fixedDeltaTime; physicsScene.Simulate(Time.fixedDeltaTime); } } // https://stackoverflow.com/questions/45484868/predict-the-position-of-a-rigidbody-object-in-x-second })); }
public override void SyncBall(Ball ball) { Packet.MsgSvrCli_SyncBall_Ntf ntf = new Packet.MsgSvrCli_SyncBall_Ntf(); Packet.Ball obj = new Packet.Ball(); obj.id = ball.id; obj.localPosition = ball.transform.localPosition; obj.rotation = ball.transform.rotation; obj.velocity = ball.rigidBody.velocity; ntf.ball = obj; foreach (Session session in sessions) { session.Send(ntf); } }