VR movement in Unity

Hi forum.

I tried to follow this tutorial on youtube to be able to walk through my animation in Unity.
I followed this tutorial on how to:

Unfortunately it does not work and I am thrown this error:
UnassignedReferenceException: The variable vrCamera of VRLookWalk has not been assigned.
You probably need to assign the vrCamera variable of the VRLookWalk script in the inspector.

How can I fix it? What am I doing wrong? Can somebody please tell me what I should type instead?
My code looks like the one in the tutorial, but maybe I have missed something, eventhough I have doublechecked many times.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VRLookWalk : MonoBehaviour {
public Transform vrCamera;

public float toggleAngle = 30.0f;

public float speed = 3.0f;

public bool moveForward;

private CharacterController cc;

// Start is called before the first frame update
void Start (){
cc = GetComponent();
}
// 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);

cc.SimpleMove(forward * speed);
}
}
}

Regards

Kenni

I think your script is fine, maybe you should check your inspector, the “vrCamera” need to be assigned. (Checkout at the tutorial video @4:35)

4830095--463586--upload_2019-8-7_9-47-27.jpg

On the right is what my inspector looks like. I dont know what I should change? Where do I assign the vrCamera?

Please check attached image.

Thanks :slight_smile:

I have dragged it there, but I still cant move. It is called camera in the left pane, so instead of calling it vrCamera in the code, should I then change it to camera?

I think the name of “vrCamera” is not the issue.

you could try to debug log the vrCamera.eulerAngles.x to check why the “moveForward” not true.

4830305--463628--upload_2019-8-7_10-37-6.png
this is my entire code so far (now seen in a different windows)

How do I find the bebug thing you mention? (Sorry, Im new to Unity and not very good at it, and when it comes to coding in it Im lost.)

Try this and run, and check the unity’s console window.

void Update () {

Debug.Log("vrCamera.eulerAngles.x: "+vrCamera.eulerAngles.x);

if (vrCamera.eulerAngles.x >= toggleAngle && vrCamera.eulerAngles.x < 90.0f){
moveForward = true;
}
else {
moveForward = false;
}

4830410--463640--upload_2019-8-7_10-57-12.png

Sadly that didnt work :frowning:

Add “Debug.Log” is a debug procedure to verify why it’s not work.

Press Ctrl+Shift+C to open unity’s console window and run, then move the camera and check the console output to see the value of eulerAngles.x. The moveForward will be true while the eulerAngles.x is between toggleAngle and 90.0f degrees.

4830725--463652--upload_2019-8-7_12-2-24.png

4830725--463655--upload_2019-8-7_12-2-56.png

4830725--463658--upload_2019-8-7_12-3-40.png

The numbers are changing as you can see, but still no movement though?

Could it be because there is something I havent downloaded from the store? Or is it because my script is “greyed out” in the inspector and that does something to it? (the text is not black as the rest)
4831136--463721--upload_2019-8-7_13-53-44.png

While you run the application and move your head(camera) look down, the angle X should be over 30 degrees.

I am. And yet nothing happens

Look Downward, it will automatically move :slight_smile: