Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
NullReference's avatar
NullReference
Honored Guest
13 years ago

Forward vector?

How do you get the direction the player is currently looking as a vector? Like if you needed to raycast straight forward for instance. Normally I would use PlayerCamera.transform.forward but that is obviously not possible with the stereo rendering set up the rift has.

6 Replies

Replies have been turned off for this discussion
  • Marbas's avatar
    Marbas
    Honored Guest
    You should be able to get the forward vector from the parent object of the stereo cameras.
  • I added a spotlight to my player. It didn't follow the tracking on all 3 axis until I attached it to the Right Camera, under CameraController under PlayerController. Why it didn't work at a higher level, or with the Left Camera, I don't know, but for an easy fix, make sure what you're doing is rooted at the CameraRight.
  • "Marbas" wrote:
    You should be able to get the forward vector from the parent object of the stereo cameras.


    That is what I thought as well, but that object doesn't rotate on the X axis.
  • Get a reference to the Right Camera game object and then:

    camerRef.transform.forward;
  • So the right camera is guaranteed to face directly forward from the center of the screen? Why is that?
  • "NullReference" wrote:
    So the right camera is guaranteed to face directly forward from the center of the screen? Why is that?


    Right Camera is on Layer 0, all orientation tracking is applied to this camera and the others use its transform information.

    In OVRCamera:SetCameraOrientation()

    // Main camera has a depth of 0, so it will be rendered first
    if(gameObject.camera.depth == 0.0f)


    The center doesn't matter because its an orientation vector, it doesn't matter where it is. If you want the centre of the eyes you will need to derive that some other way. I personally have an additional child object on the Right Camera that is offset in its local space to be in the centre. I do Raycasts from this objects Forward vector when I need to.