I need some help with photon. I have a fast PhotonView object and its master is constantly changing. Sometimes this object is teleported on other devices. Do you know the solution? how can i create a solution
I tried using RPC and the result was still the same.
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
public class CustomTransformView : MonoBehaviourPunCallbacks, IPunObservable
{
private Rigidbody rigidbody;
private void Awake()
{
rigidbody = GetComponent<Rigidbody>();
QualitySettings.vSyncCount = 0;
Application.targetFrameRate = 45;
PhotonNetwork.SendRate = 30;
PhotonNetwork.SerializationRate = 25;
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
stream.SendNext(rigidbody.position);
stream.SendNext(rigidbody.rotation);
stream.SendNext(rigidbody.velocity);
}
else
{
// Bu oyuncu veri alıyor
Vector3 targetPosition = (Vector3)stream.ReceiveNext();
Quaternion targetRotation = (Quaternion)stream.ReceiveNext();
Vector3 targetVelocity = (Vector3)stream.ReceiveNext();
float lag = Mathf.Abs((float)(PhotonNetwork.Time - info.timestamp));
float lerpTime = lag * 50f; // Geçiş zamanlamasını ayarlayın
print(lag);
if (BallManager.Instance.UserId == "")
{
lerpTime = 25 * lag; // Geçiş zamanlamasını ayarlayın
}
else
{
lerpTime = lag * 50; // Geçiş zamanlamasını ayarlayın
}
// Rigidbody bileşenlerinin konum, rotasyon ve hızını pürüzsüz bir şekilde güncelleyin
rigidbody.position = Vector3.Lerp(rigidbody.position, targetPosition, lerpTime);
rigidbody.rotation = Quaternion.Lerp(rigidbody.rotation, targetRotation, lerpTime);
rigidbody.velocity = Vector3.Lerp(rigidbody.velocity, targetVelocity, lerpTime);
}
}
}