Translate CameraRig Along Gyroscopic GetComponent Vector

Hi,

Preface: I am pretty much totally new to C#, but I had some previous python experience doing some small study projects on Arduino.

I am trying to utilize the google cardboard SDK package for the stereoscopic camera effect, and child it to a parent camera rig, where I used the basic Unity translate script from the tutorials page.

The information I am trying to find is how to modify the movement code attached to my CameraRig, to be related to the head angle’s Z direction, but rotated down into the global XZ plane (the magenta vector would be the one I hope to use in the CameraRig script). See this diagram:

This is simply just beyond me to figure out on my own.

The CameraRig movement script:

using UnityEngine;

public class RigMovement: MonoBehaviour
{
    public float moveSpeed = 10f;
    public float turnSpeed = 50f;

    private Rigidbody playerRigidbody;

    void Awake()
    {
        //Get references
        playerRigidbody = GetComponent<Rigidbody>();
    }

    void Update()
    {
        if (Input.GetKey(KeyCode.UpArrow))
            transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);

        if (Input.GetKey(KeyCode.DownArrow))
            transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime);

        if (Input.GetKey(KeyCode.LeftArrow))
            transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);

        if (Input.GetKey(KeyCode.RightArrow))
            transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
    }
}

I am unsure of what to link here for the Cardboard SDK, but I downloaded it from this location, and attached the camera asset as a child to the rig: Quickstart for Google VR SDK for Unity with Android  |  Google for Developers

I imagine it would be a GetComponent from the SDK script where I should begin searching, but I think I have to figure out how to make a derivative of a vector a public element?

Thanks for any help you can provide!

Best,

Kevin

Also if there just isn’t enough information to respond, could you please let me know what other information I should include?

I don’t understand what you’re trying to achieve exactly. Move character when head rotation is looking down?

Thanks Selzier. I am looking for something more basic (I think).

I am trying to figure out how to make my character move forward (by the head’s local direction) in the global XZ plane, regardless what angle the head is up or down locally.

Like this:
Start preview
Hit W to move forward
(VR) head looks left
Hit W to go the direction the head is looking, but along the XZ global plane.

Is that more clear?

Kevin

This is very close:

Also we have a movement pack:

Hah! That is so funny, I just found this video myself. Thank you.

1 Like