/// <summary> /// Calculates an estimated position based on the last synchronized position, /// the time when the last position was received and the movement speed of the object /// </summary> /// <returns>Estimated position of the remote object</returns> public Vector3 GetExtrapolatedPositionOffset() { float timePassed = (float)(PhotonNetwork.Time - m_LastSerializeTime); if (m_Model.ExtrapolateIncludingRoundTripTime == true) { timePassed += (float)PhotonNetwork.GetPing() / 1000f; } Vector3 extrapolatePosition = Vector3.zero; switch (m_Model.ExtrapolateOption) { case PhotonTransformViewPositionModel.ExtrapolateOptions.SynchronizeValues: Quaternion turnRotation = Quaternion.Euler(0, m_SynchronizedTurnSpeed * timePassed, 0); extrapolatePosition = turnRotation * (m_SynchronizedSpeed * timePassed); break; case PhotonTransformViewPositionModel.ExtrapolateOptions.FixedSpeed: Vector3 moveDirection = (m_NetworkPosition - GetOldestStoredNetworkPosition()).normalized; extrapolatePosition = moveDirection * m_Model.ExtrapolateSpeed * timePassed; break; case PhotonTransformViewPositionModel.ExtrapolateOptions.EstimateSpeedAndTurn: Vector3 moveDelta = (m_NetworkPosition - GetOldestStoredNetworkPosition()) * PhotonNetwork.SerializationRate; extrapolatePosition = moveDelta * timePassed; break; } return(extrapolatePosition); }
public override void OnConnectedToMaster() { // Set custom some player properties before joining room Hashtable playerProperties = new Hashtable(); playerProperties["Ping"] = PhotonNetwork.GetPing(); PhotonNetwork.LocalPlayer.SetCustomProperties(playerProperties); // Fire Event if (OnConnectedToPhotonMaster != null && !isConnectedToMaster) { OnConnectedToPhotonMaster(); Debug.Log("Connected to Photon master server"); isConnectedToMaster = true; } }
private void Update() { // TODO: Profile this in some way and see if its more overhead that just sending an RPC between two clients and checking the RTT if (isConnectedToRoom) { Hashtable playerCustomProperties = PhotonNetwork.LocalPlayer.CustomProperties; // If ping changed, update it object otherPlayerPing = playerCustomProperties["Ping"]; if (otherPlayerPing != null) { if (PhotonNetwork.GetPing() != (int)otherPlayerPing) { playerCustomProperties["Ping"] = PhotonNetwork.GetPing(); PhotonNetwork.LocalPlayer.SetCustomProperties(playerCustomProperties); } } } }