Search Unity

Help Wanted Photon 2 move/rotate child

Discussion in 'Multiplayer' started by Atix07, Oct 25, 2020.

  1. Atix07

    Atix07

    Joined:
    Jul 27, 2013
    Posts:
    182
    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.

    Code (CSharp):
    1. public class headTilt : MonoBehaviourPun, IPunObservable
    2. {
    3.  
    4.     public Camera cameraRot;
    5.     public PhotonView PV;
    6.  
    7.     private Vector3 objRot;
    8.     public Transform head;
    9.  
    10.     // Use this for initialization
    11.     void Start()
    12.     {
    13.         cameraRot = this.GetComponentInChildren<Camera>();
    14.         PV = this.GetComponent<PhotonView>();
    15.     }
    16.  
    17.     void LateUpdate()
    18.     {
    19.         if (PV.IsMine)
    20.         {
    21.             Vector3 tmp = cameraRot.transform.localEulerAngles;
    22.             tmp = cameraRot.transform.localEulerAngles;
    23.             tmp.x = 0f;
    24.             tmp.y = 0f;
    25.             tmp.z -= cameraRot.transform.localEulerAngles.x;
    26.             objRot = tmp;
    27.  
    28.             head.transform.localEulerAngles = objRot;
    29.         }
    30.     }
    31.  
    32.     public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    33.     {
    34.         if (stream.IsWriting)
    35.         {
    36.             stream.SendNext(objRot);
    37.         }
    38.         else
    39.         {
    40.             this.objRot = (Vector3)stream.ReceiveNext();
    41.         }
    42.     }
    43. }
    Thanks!
     

    Attached Files:

    Last edited: Oct 26, 2020
  2. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,586
  3. Atix07

    Atix07

    Joined:
    Jul 27, 2013
    Posts:
    182
  4. Atix07

    Atix07

    Joined:
    Jul 27, 2013
    Posts:
    182
    Ok.. soo I tried debuging it and nothing appears on console.

    Code (CSharp):
    1. public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    2.     {      
    3.         if (stream.IsWriting)
    4.         {
    5.             Debug.Log("is Writing");
    6.             stream.SendNext(head.transform.localEulerAngles);
    7.         }
    8.         else
    9.         {
    10.             Debug.Log("is reading");
    11.             this.head.transform.localEulerAngles = (Vector3)stream.ReceiveNext();
    12.         }
    13.     }
     
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,691
    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).
     
  6. Atix07

    Atix07

    Joined:
    Jul 27, 2013
    Posts:
    182
    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.
     
    tobiass likes this.
  7. lucarodenburg33

    lucarodenburg33

    Joined:
    Feb 10, 2020
    Posts:
    1
    Ever got it to work?
    Trying the same thing :/
     
    Last edited: Sep 1, 2021
unityunity