Photon 2 move/rotate child

Hello!

Im new to the photon. Im trying my rotate my players head, up and down according to cameras rotation. Its fully working in local but cant make it work in multiplayer.

public class headTilt : MonoBehaviourPun, IPunObservable
{

    public Camera cameraRot;
    public PhotonView PV;

    private Vector3 objRot;
    public Transform head;

    // Use this for initialization
    void Start()
    {
        cameraRot = this.GetComponentInChildren<Camera>();
        PV = this.GetComponent<PhotonView>();
    }

    void LateUpdate()
    {
        if (PV.IsMine)
        {
            Vector3 tmp = cameraRot.transform.localEulerAngles;
            tmp = cameraRot.transform.localEulerAngles;
            tmp.x = 0f;
            tmp.y = 0f;
            tmp.z -= cameraRot.transform.localEulerAngles.x;
            objRot = tmp;

            head.transform.localEulerAngles = objRot;
        }
    }

    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.IsWriting)
        {
            stream.SendNext(objRot);
        }
        else
        {
            this.objRot = (Vector3)stream.ReceiveNext();
        }
    }
}

Thanks!

6453642--722985--Yeni proje.gif

Have you done step 5 in this example Pun 2 7 - Player Networking | Photon Engine ?

I was missing photonview.isMine but still not working.

Maybe because its a bone that Im rotating? I updated the code in my first post.

Ok… soo I tried debuging it and nothing appears on console.

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {      
        if (stream.IsWriting)
        {
            Debug.Log("is Writing");
            stream.SendNext(head.transform.localEulerAngles);
        }
        else
        {
            Debug.Log("is reading");
            this.head.transform.localEulerAngles = (Vector3)stream.ReceiveNext();
        }
    }

Then the script is not in the list of observed components.
Latest PUN 2 should detect this. Else, you can manually drag and drop the component to the PhotonView.
Also, 2 players need to be in the room to run this (else, PUN 2 is not sending to anyone).

Thanks for the answer!

Yeah I was testing alone so that was why I didnt see any anything on the console. Now Im pretty sure that data is sent and read because tested with 2 players. Still not working tho. I think local rotation and localEularAngles are not working because its relative to the parent transform’s rotation.

1 Like

Ever got it to work?
Trying the same thing :confused:

still trying and not working either