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();
}
}
}
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).
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.