Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Game Development

Moving the user with VR

I'm using the google cardboard SDK and i have a script attached to the child "Head" in the GvrMain prefab. There's also a Character controller connected and the vrCamera variable has been set to the "Head" object to this so that i can move the user based on the code which will follow.

https://drive.google.com/file/d/0B0QLbDLfJn6_dFBRTXpId09vaEU/view

The issue i'm having is that i want to move the character when the user tilts their head at an angle, all this works fine but the issue is that when the simpleMove function is called nothing is happening... I've logged to see if any of the variables upto the point are empty but none of them seem to be; just this function doesn't seem to be getting called. Code below.

using UnityEngine;
using System.Collections;

public class VRLookWalk : MonoBehaviour {

    public Transform vrCamera;

    public float toggleAngle = 30.0f;

    public float speed = 3.0f;

    public bool moveForward;

    private CharacterController myCC;

    // Use this for initialization
    void Start () {

        myCC = GetComponent<CharacterController> ();


    }

    // Update is called once per frame
    void Update () {

        if (vrCamera.eulerAngles.x >= toggleAngle && vrCamera.eulerAngles.x < 90.0f) 
        {

            moveForward = true;

        } else {
            moveForward = false;
        }

        if (moveForward)
        {

        Vector3 forward = vrCamera.TransformDirection (Vector3.forward);
            myCC.SimpleMove (Vector3(0.0, -0.7, 0.7) * speed);
        }   
    }
}

Nick Pettit, ​Do you reckon you could offer any guidance at all?

1 Answer

Nick Pettit
STAFF
Nick Pettit
Treehouse Teacher

I can't really provide any help because I'm not familiar with Google Cardboard at all. Sorry!