Smooth Manual Synchronization Of Rigidboy

Options
Hey there, I am using the following script to manually synchronize elements position and rotation. The elements are interactables, therefore, they can be grabbed, thrown. But before grabbing I change the ownership to the player who is grabbing. However, it works but the movement is not smooth. When a player tries to grab it, the element tries to go back to the previous position. I can't use PhotonTransformView as I am doing it for AR. Any suggestion will be appreciated. Thanks


public class InteractableManualSyncronization : MonoBehaviour, IPunObservable
{

public Rigidbody rb;
public InteractableObjectView interactble;
public PhotonView photonView;

public Vector3 correctPos = Vector3.zero; //We lerp towards this
public Quaternion correctRot = Quaternion.identity; //We lerp towards this


private void Awake()
{
rb = GetComponent<Rigidbody>();
interactble = GetComponent<InteractableObjectView>();
photonView = GetComponent<PhotonView>();
}

private void FixedUpdate()
{
if (photonView.IsMine == true ) return;
float distance = Vector3.Distance(transform.position, this.correctPos);

if (distance < 2f)
{
transform.position = Vector3.Lerp(transform.position, this.correctPos, Time.deltaTime * 5);
transform.rotation = Quaternion.Lerp(transform.rotation, this.correctRot, Time.deltaTime * 5);
}
else
{
transform.position = this.correctPos;
transform.rotation = this.correctRot;
}


}

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
stream.SendNext(rb.position - FindObjectOfType<GroundHandler>().transform.position);
stream.SendNext(rb.rotation);
stream.SendNext(rb.isKinematic);
stream.SendNext(rb.useGravity);

if (interactble.hasQuickInteractions)
{
if (interactble.GetComponentInChildren<WeaponView>())
{
stream.SendNext(interactble.GetComponentInChildren<WeaponView>().canShoot);
stream.SendNext(interactble.GetComponentInChildren<WeaponView>().totalBullets);
stream.SendNext(interactble.GetComponentInChildren<WeaponView>().currentBullets);
}
else if (interactble.GetComponentInChildren<CanonView>())
{
stream.SendNext(interactble.GetComponentInChildren<CanonView>().canShoot);
stream.SendNext(interactble.GetComponentInChildren<CanonView>().totalBullets);
stream.SendNext(interactble.GetComponentInChildren<CanonView>().bulletsInCanon);
}
}
}
else
{
this.correctPos = (Vector3)stream.ReceiveNext() + FindObjectOfType<GroundHandler>().transform.position;
this.correctRot = (Quaternion)stream.ReceiveNext();
rb.isKinematic = (bool)stream.ReceiveNext();
rb.useGravity = (bool)stream.ReceiveNext();

if (interactble.hasQuickInteractions)
{
if (interactble.GetComponentInChildren<WeaponView>())
{
interactble.GetComponentInChildren<WeaponView>().canShoot = (bool)stream.ReceiveNext();
interactble.GetComponentInChildren<WeaponView>().totalBullets = (int)stream.ReceiveNext();
interactble.GetComponentInChildren<WeaponView>().currentBullets = (int)stream.ReceiveNext();
}
else if (interactble.GetComponentInChildren<CanonView>())
{
interactble.GetComponentInChildren<CanonView>().canShoot = (bool)stream.ReceiveNext();
interactble.GetComponentInChildren<CanonView>().totalBullets = (int)stream.ReceiveNext();
interactble.GetComponentInChildren<CanonView>().bulletsInCanon = (int)stream.ReceiveNext();
}
}
}
}
}