Hello, I was trying to make my Character controller walk in a straight line and if he/she looks left or right - stop, look up or down - still walk.
I have tried
using UnityEngine;
using System.Collections;
public class VRLookWalkWalking : MonoBehaviour {
public Transform vrCamera;
public float toggleAngle = -10.0f;//when you look on X axis at this angle you will walk was 30.0f
public float speed=3.0f;//speed at which you walk
public bool moveForward;
public CharacterController cc;
// Use this for initialization
void Start () {
cc.GetComponent<CharacterController> ();
}
// Update is called once per frame
void Update () {
if (vrCamera.localEulerAngles.y>= toggleAngle && vrCamera.localEulerAngles.y < 10.0f) {
moveForward = true;
} else {
moveForward = false;
}
if (moveForward) {
Vector3 forward = vrCamera.TransformDirection (Vector3.forward);
cc.SimpleMove (forward * speed);
}
}
}
It did not work. I decided to create a cube in front of the path, make it a trigger. But all the changes to the script above did not work as well. Any help is appreciated. Thank you