VR Character controller goes up when camera looks up

Hello, I have the GvrMain in my projects. Character controller is attached to the camera. When camera looks down between 30and 90 degrees - character moves forward. This script attached to it:

public class VRLookWalk : MonoBehaviour {
public Transform vrCamera;
public float toggleAngle=30.0f;
public float speed = 3.0f;
public bool moveForward;
public CharacterController cc;

// Use this for initialization
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);
}
}
}

All is good, but only when I look up - character lifts from the ground and goes up as well. Any suggestions, please. I am new to Unity.Thank you

you mix the the camera direction with the move direction of the cc, thats a bad idea and crys for problems, , build it easier: i assume you want to move the character forward when the camera “look angle” is between 30 and 90 degree, right?
if so you can try change the lines
Vector3 forward = vrCamera.TransformDirection (Vector3.forward);
cc.SimpleMove (forward * speed);

to:
cc.SimpleMove (cc.transform.forward * speed * Time.deltaTime);

Edit: oh and the Camera should be a child of the CharacterController not the other way around

1 Like