Object Transform issues after Ownership Transfer

Options
First let me say that this is a wonderful plugin/toolset for getting a game project up and running with minimal hard work on the developers side. This plugin is a great asset to the indie community and I am grateful such a solution exists. On to my issue!

I have a project where players are allowed to physically manipulate objects within a scene. This all works currently using the provided ownership transfer protocol established in the tutorial on the main site. I am, however, running into a strange quirk. When any player grabs an object and moves it from one place to another after another player has moved it, it will revert back to its position where the previous player picked it up or where it was originally in the scene.

Within the Observer for movable objects I am assigning the incoming data from the owner to a separate value other than the transform and then in the update loop I am Lerping to that value. I can't seem to find the point at which it is retaining the old data and reassigning it to the transform. Below is written from memory as I am not currently at my home PC, but I think it conveys the script pretty well. Mind you I am getting no error messages or warnings, just strange behavior ingame. The objects will still move to where you place them, but they Lerp from the original position that the previous player picked them up from to where you grab them. I suspect it has something to do with using these containers to hold the old position, but I'm a bit stumped as to why.
public Vector3 CorrectObjectPosition;
public Vector3 CorrectObjectRotation;

public void Update()
{
       if(!photonview.isMine)
       {
       transform.position = Vector3.Lerp(transform.position, CorrectObjectPosition, Time.deltaTime * 5f);
       transform.rotation = Vector3.Quaternion(transform.rotation, CorrectObjectRotation, Time.deltaTime * 5f);
       }
}

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
        if(stream.IsWriting && photonview.isMine)
        {
                stream.SendNext(transform.position);
                stream.SendNext(transform.rotation);
        }
         if(stream.IsReading && !photonview.isMine)
        {
                CorrectObjectPosition = (Vector3)stream.RecieveNext();
                CorrectObjectRotation = (Quaternion)stream.RecieveNext();
        }
}

Comments

  • Tobias
    Options
    Let me say thanks for the kind words in the intro. Good to read Photon makes things easier :)

    I guess the issue is in the details. The script is using a helper value CorrectObjectPosition. It's only updated when you don't own the GO. When you had control and hand that over to someone else, this variable gets used again but by now, it has old values! It's only updated again, when the new owner sets a position and that might take a moment due to lag.
    That's just a guess. I didn't test it properly but my guess is: If you update the Correct* positions when handing over ownership, then you can fix the issue.