I know a couple of folks here use Ootii's Camera Controller and his Motion Controller packages to replace ORK's built-in solution and I've heard good things so I grabbed the Camera Controller on sale over the weekend.

I tried to integrate it with ORK but it requires grabbing a transform from the player GameObject as an anchor. ORK instantiates the player from a prefab and the CC of course can't find it. He posted a couple of lines for finding the "Player" tag and they work if placed in Update() of a script attached to the Camera Controller but not Start().

GameObject lPlayer = GameObject.FindGameObjectWithTag("Player");
CameraController lCameraRig = Component.FindObjectOfType();
lCameraRig.Anchor = lPlayer.transform;

Should this be a coroutine in Start()? Since I'm new to coding I need some tips on where/how to place this.
  • Are you using Motion Controller as well or just the Camera Controller? If you're using MC, then you should just be able to leave the Anchor field empty and then MC will find the Camera Rig (assuming "Find" is checked) once the player prefab is instantiated.

    But I'm going to assume you aren't. :-)

    This code doesn't work in Start() because ORK won't have spawned the player yet when the CameraController runs its Start() method. So you'll need to wait for the player to spawn.

    If you attach this script to your CameraController, it should do the trick:

    using UnityEngine;
    using System.Collections;
    using com.ootii.Cameras;

    [RequireComponent(typeof(CameraController))]
    public class CameraRigBridge : MonoBehaviour
    {
    private GameObject mPlayer;
    private CameraController mCameraController;

    private void Start()
    {
    mCameraController = GetComponent<CameraController>();
    StartCoroutine(FindPlayer());
    }

    private IEnumerator FindPlayer()
    {
    do
    {
    mPlayer = GameObject.FindGameObjectWithTag("Player");
    yield return null;
    } while (mPlayer == null);

    mCameraController.Anchor = mPlayer.transform;
    }
    }



    Now, one thing you'll discover in fairly short order is that the Camera Rig paradigm doesn't quite work flawlessly with how ORK manages the camera. Because ootii has the actual Camera object parented to the Camera Rig and has the rig doing the movement, you're going to run into problems if you use ORK to move the camera or set its position. You probably also want ORK to forward Camera control blocking as well.

    So instead of the component above, place this one ON THE CAMERA (not the Camera Controller):

    using UnityEngine;
    using System.Collections;
    using com.ootii.Cameras;

    [RequireComponent(typeof(Camera))]
    public class ootiiCameraBridge : MonoBehaviour
    {
    [Tooltip("Block player camera control when ORK enables the Camera block? (Requires this component specified in Custom Controls.)")]
    public bool _EnableCameraBlocking = true;

    private GameObject mPlayer;
    private Camera mCamera;
    private CameraController mCameraController;

    private void Start()
    {
    mCamera = GetComponent<Camera>();
    mCameraController = transform.parent.gameObject.GetComponent<CameraController>();

    StartCoroutine(FindPlayer());
    }

    private void OnEnable()
    {
    if (mCamera != null)
    {
    // Zero out the camera position and rotatation values
    mCamera.transform.position = Vector3.zero;
    mCamera.transform.localPosition = Vector3.zero;
    mCamera.transform.rotation = Quaternion.identity;
    mCamera.transform.localRotation = Quaternion.identity;
    }

    if (mCameraController == null || mCameraController.InputSource == null) { return; }

    if (_EnableCameraBlocking) { mCameraController.InputSource.IsEnabled = true; }
    }

    private void OnDisable()
    {
    if (mCameraController == null || mCameraController.InputSource == null) { return; }

    if (_EnableCameraBlocking) { mCameraController.InputSource.IsEnabled = false; }
    }

    private IEnumerator FindPlayer()
    {
    do
    {
    mPlayer = GameObject.FindGameObjectWithTag("Player");
    yield return null;
    } while (mPlayer == null);

    mCameraController.Anchor = mPlayer.transform;
    }
    }


    Whenever ORK stops blocking camera control, this component will be re-enabled and it will zero out any of the movement or rotation that ORK applied. If you want the camera to stay in the same position, then you'll need to zero out those values and copy them to the Camera Controller's transform.

    Ultimately, a set of custom Event nodes that duplicate the functionality of all of ORK's camera nodes would be better, but it hasn't been a high priority on my to-do list. :-)
  • Oh man, thanks so much!

    And yes, using just the CC for now although his motion controller is on sale this week too and I've been considering that too so might take the plunge there as well.
Sign In or Register to comment.