Photon PUN2 - Non-Rigidbody Lag Compensation and Jittery Cars
Options
I have made a very simple car game.
I am not syncing PhotonTransformView but instead doing lag compensation using LERP (well tried doing movetowards but it was more laggy and jittery).
I am using PurePool with PUN2 (pool) but don't think it should matter ?
Some of code snippets here:
Local Player moves using
Remote Player compensation movement
PurePool
Actual behavior, both are PC builds on same PC and same network and India/Asia server
DebugView of the LagCompensation stats even when both cars were driving almost side by side
I am not syncing PhotonTransformView but instead doing lag compensation using LERP (well tried doing movetowards but it was more laggy and jittery).
I am using PurePool with PUN2 (pool) but don't think it should matter ?
Some of code snippets here:
Local Player moves using
///////////////////////////////////////////////////////////////// ///Player Movement // Move the player forward /////////////////////////////////////////////////////////////////// /// if (MultiplayerManager.Instance.checkIfObjectIsMine(this.gameObject)) { thisTransform.Translate(Vector3.forward * Time.deltaTime * speed * speedMultiplier, Space.Self); }
Remote Player compensation movement
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.IsWriting) { stream.SendNext(this.transform.position); stream.SendNext(this.transform.rotation); } else { //Network player, receive data latestPos = (Vector3)stream.ReceiveNext(); latestRot = (Quaternion)stream.ReceiveNext(); //Lag compensation currentTime = 0.0f; lastPacketTime = currentPacketTime; currentPacketTime = info.SentServerTime; positionAtLastPacket = transform.position; rotationAtLastPacket = transform.rotation; } } public void Update() { if (!myPhotonView.IsMine) { //Lag compensation timeToReachGoal = currentPacketTime - lastPacketTime; currentTime += Time.deltaTime; //Update remote player transform.position = Vector3.Lerp(positionAtLastPacket, latestPos, (float)(currentTime / timeToReachGoal)); transform.rotation = Quaternion.Lerp(rotationAtLastPacket, latestRot, (float)(currentTime / timeToReachGoal)); } }
PurePool
using Photon.Pun; using Umbrace.Unity.PurePool; using UnityEngine; namespace Umbrace.Unity.PurePool.Photon { public class PunPoolingSetup : MonoBehaviour { [SerializeField, HideInInspector] private PrefabPool punPrefabPool; private void Start() { // Create the PrefabPool object, which is the bridge between PUN and Pure Pool. this.punPrefabPool = new PrefabPool(); // Set the manager to load by name from the Resources folders. // This is required as most objects spawned by PUN will not be set up in the manager already, and will need to be loaded. NamedGameObjectPoolManager.Instance.UseResources = true; // Assign the manager, so it knows how to acquire and release from the pools. this.punPrefabPool.Manager = NamedGameObjectPoolManager.Instance; // Set PUN to use the PrefabPool object. PhotonNetwork.PrefabPool = punPrefabPool; } private void OnEnable() { // Set PUN to use the PrefabPool object again. PhotonNetwork.PrefabPool = this.punPrefabPool; } } }
Actual behavior, both are PC builds on same PC and same network and India/Asia server
DebugView of the LagCompensation stats even when both cars were driving almost side by side
0
Comments
-
bump0
-
I wish someone could help me out on what's wrong here. I spent last 4 days trying all the methods and information available online and to my understanding still couldn't fix it and am now having to ditch photon completely (well git commited it at this point) and moving towards mirror0