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

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

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

DanieleSuppo
2022-12-01 16:54:22

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!

Comments

Tobias
2022-12-05 10:51:38

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
2022-12-09 07:28:09

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 && valuesrecieve

d    
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? ^^

DanieleSuppo
2022-12-09 13:09:49

I've solved enabling and disabling the PhotonTransformView component:

public

  • PhotonView pv;

public bool

  • imMovingTheGameobject;

List ptvList = new

  • List();

  • void Start()

  • {

foreach (var observed in

  • pv.ObservedComponents)

  • {

if (observed.gameObject.GetComponent() != null

  • )

  • {

  • PhotonTransformView phv = observed.gameObject.GetComponent();

ptvList.Add

  • (phv);

  • }

  • }

  • }

void

  • Update()

  • {

if

  • (!pv.IsMine)

  • {

SetTransformViewEnabled(true

  • );

  • }

  • else

  • {

  • SetTransformViewEnabled(imMovingTheGameobject);

  • }

  • }


void SetTransformViewEnabled(bool value

  • )

  • {

foreach (var ptv in

  • ptvList)

  • {

  • if (ptv.enabled != value)

ptv.enabled = value

  • ;

  • }

  • }

Back to top