Hi everyone!
I’ve been trying to sync up 2 different oculus quests acting as clients to a server and have them both render their own separate cameras. I’ve created a prefab with a camera rig, network object, and network transform and can get both players to connect, however upon the second player connecting, the cameras switch. Positionally and rotationally the hmd’s send the data correctly, and if there is only one client connected, it shows the proper camera. Server side it shows the hmd’s pov as the correct camera as well, however in the headset it’s not the same because when the second player connects, the hmd’s immediately start showing each others pov, and not their own. Here is the code I am using for the movement and cameras. Any help or suggestions would be appreciated!
using UnityEngine;
using MLAPI;
[RequireComponent(typeof(CharacterController))]
public class OculusMovement : NetworkBehaviour
{
private readonly bool HmdRotates = true;
CharacterController Controller = null;
protected OVRCameraRig CameraRig = null;
protected Transform centerEye = null;
protected Transform root = null;
protected OVRCameraRig[] CameraRigs;
void Start()
{
var p = CameraRig.transform.localPosition;
p.z = OVRManager.profile.eyeDepth;
CameraRig.transform.localPosition = p;
Controller = gameObject.GetComponent<CharacterController>();
}
void Awake()
{
CameraRigs = gameObject.GetComponentsInChildren<OVRCameraRig>();
CameraRig = CameraRigs[0];
}
void Update()
{
CameraRig.UpdatedAnchors += UpdateTransform;
}
public void UpdateTransform(OVRCameraRig rig)
{
root = CameraRig.trackingSpace;
centerEye = CameraRig.centerEyeAnchor;
if (HmdRotates)
{
// Transforms the HMD
Vector3 prevPos = root.position;
Quaternion prevRot = root.rotation;
transform.SetPositionAndRotation(new Vector3(centerEye.position.x, centerEye.position.y, centerEye.position.z), Quaternion.Euler(centerEye.rotation.eulerAngles.x, centerEye.rotation.eulerAngles.y, centerEye.rotation.eulerAngles.z));
root.SetPositionAndRotation(prevPos, prevRot);
}
}
}