Gameobject is jittering when its ownership is transferred to another user!

Options

Hello, I have a very big problem: I have a Gameobject that can be moved by 2 users, and basically each of them take its ownership pressing a button. Unfortunately, after some movements (just position and rotation), when one of them take its ownership it "jitter" quite a lot (it move to another position and back to the right one) on the user that "lost" the ownership (but not on the user that is the new owner).

This issue does not happen just in my game, but in the official PUN tutorial too!

It's quite easy to reproduce:

1 - create a Cube, with its PhotonView and PhotonTransformView

2 - create a simple script, attached to the cube, with the function "pv.RequestOwnership();" and a button that call this function

3 - in gameplay, user1 can move and rotate the cube with the mouse in the scene, and its position/rotation are updated on user2

4 - user2 press the button to take the ownership, and to move and rotate the cube, and its position/rotation are updated on user1

5 - after a couple of movements, and changing from user1 and user2, you will see that the cube, on the user that just lost the ownership, will move around its position a bit

Is it a (huge) bug?

Many thanks!

Answers

  • Tobias
    Options

    If a user just passed control to the other, this other player didn't send an update yet but the interpolation is still trying to smoothly move the cube from a to b. I guess this could cause jitter.

    The PhotonTransformView is considered a basis implementation for you to expand on. You may want to replace it with a customized version that prevents interpolation when ownership was handed over. If this is a physical object, make sure IsKinematic is applied, so the physics engine is not moving the object, too.

    Controlling one object with multiple users is a bit beyond PUN's capabilities. I would recommend using Fusion for this kind of interaction (and run the simulation on a Host/Server). It's been used to toss objects from user to user in VR.

  • Schuasta
    Schuasta
    edited December 2022
    Options

    I have this problem too with PUN2. I already set isKinematic, but the object jitter first to the old position and after that there is no problem anymore. It only "jitter" for the other ones, if the ownership gets transfered again.

    So how could i prevent the interpolation when the ownership is handed over? Any ideas?

    Thanks in Advance ;)


    EDIT: Okay finally i got it to work. In my Example im just syncing an EulerAngle Y (m_eulerAngleY). Maybe there is a better Solution for this, but i added IPunOwnershipCallbacks in Custom Version from the TransformView and added this:

    public void OnOwnershipTransfered(PhotonView targetView, Player previousOwner)
    {
        if (previousOwner.ActorNumber == PhotonNetwork.LocalPlayer.ActorNumber)
        {
            isFirstValue = true;
        }
    }
    


    In my Update Function i will set the Angle manually and afterwards i start the Interpolation.

    //If view is not Mine && valuesrecieved
    if (isFirstValue)
    {
        m_eulerAngleY = tf.localRotation.eulerAngles.y;
        tf.localRotation = Quaternion.Euler(0, m_eulerAngleY, 0);
        isFirstValue = false;
    }
    else
        tf.localRotation = Quaternion.Lerp(tf.localRotation, Quaternion.Euler(0, m_eulerAngleY, 0), 0.03f);
    

    Maybe i can get a Feedback? ^^

  • I've solved enabling and disabling the PhotonTransformView component:

    1. public PhotonView pv;
    2. public bool imMovingTheGameobject;
    3. List<PhotonTransformView> ptvList = new List<PhotonTransformView>();
    4.  
    5. void Start()
    6.    {
    7.      foreach (var observed in pv.ObservedComponents)
    8.      {
    9.        if (observed.gameObject.GetComponent<PhotonTransformView>() != null)
    10.        {
    11.         PhotonTransformView phv = observed.gameObject.GetComponent<PhotonTransformView>();
    12.         ptvList.Add(phv);
    13.        }
    14.      }
    15.    }
    16.  
    17. void Update()
    18.    {
    19.      if (!pv.IsMine)
    20.      {
    21.       SetTransformViewEnabled(true);
    22.      }
    23.       else
    24.      {
    25.       SetTransformViewEnabled(imMovingTheGameobject);
    26.      }
    27.    }
    28.  
    29.  
    30. void SetTransformViewEnabled(bool value)
    31.    {
    32.      foreach (var ptv in ptvList)
    33.      {
    34.        if (ptv.enabled != value)
    35.         ptv.enabled = value;
    36.      }
    37.    }
    38.