Rotation is always a little off over clients?
Options
So this is something fairly straightforward but why it isn't working makes no sense to me. I've been trying to replicate the rotation of my gun's nozzle using PhotonTransformViewClassic and no matter what interpolation option I used, the rotation was always off. So I went ahead and implemented the OnPhotonSerializeView like so :
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
stream.SendNext(transform.rotation);
}
else if (stream.IsReading)
{
transform.rotation = (Quaternion)stream.ReceiveNext();
}
}
Now as I understand, this function should be called 10 times/sec and simply enough, the rotation on all the clients should be set to EXACTLY that of the owner, right? since it is literally just writing the reading a value without any processing whatsoever. But even now, there are noticeable offsets. To demonstrate this, I added a 3D text in front of the gun and printed the nozzle's rotation on it. As shown in the video below, I move around the nozzle multiple times and the values on the server and client are always different. Any ideas on how to sort this out would be greatly appreciated. Thanks!
https://www.youtube.com/watch?v=2VjuWZV-b4w&feature=youtu.be
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
stream.SendNext(transform.rotation);
}
else if (stream.IsReading)
{
transform.rotation = (Quaternion)stream.ReceiveNext();
}
}
Now as I understand, this function should be called 10 times/sec and simply enough, the rotation on all the clients should be set to EXACTLY that of the owner, right? since it is literally just writing the reading a value without any processing whatsoever. But even now, there are noticeable offsets. To demonstrate this, I added a 3D text in front of the gun and printed the nozzle's rotation on it. As shown in the video below, I move around the nozzle multiple times and the values on the server and client are always different. Any ideas on how to sort this out would be greatly appreciated. Thanks!
https://www.youtube.com/watch?v=2VjuWZV-b4w&feature=youtu.be
0
Comments
-
Anyone? hoping to bump the post up. Still stuck on this.0
-
Here is what I do to get accurate position and rotation data
float _positionLerpRate = 17.0f; float _rotationLerpRate = 5.0f; public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.IsWriting) { stream.SendNext(transform.position); stream.SendNext(transform.rotation); stream.SendNext((realPos - lastPos) * Time.deltaTime); } else { //Receive Player Position and rotation this.realPos = (Vector3)stream.ReceiveNext(); this.realRot = (Quaternion)stream.ReceiveNext(); this.velocity = (Vector3)stream.ReceiveNext(); //Account for network lag float lag = Mathf.Abs((float)(PhotonNetwork.Time - info.SentServerTime)); this.realPos += (velocity * lag); } } void Update() { if (GetComponent<PhotonView>().IsMine == false && PhotonNetwork.OfflineMode == false) { float distance = Vector3.Distance(transform.position, this.realPos); if (distance < 2f) { transform.position = Vector3.Lerp(transform.position, this.realPos, Time.deltaTime * _positionLerpRate); transform.rotation = Quaternion.Lerp(transform.rotation, this.realRot, Time.deltaTime * _rotationLerpRate); } else { transform.position = this.realPos; transform.rotation = this.realRot; } } else if (PhotonNetwork.OfflineMode == false) { lastPos = realPos; } }
0