- Home /
AutoWalk Oculus Rift
Hi: I0m new with Oculus Rift, I have made some games with Google Cardboard, and I have found an script for moving my character when he looks down with de headset, I'm trying to do the same thing in Oculus, when I look down I can star walking forward. Can anyone help me? I made this script but didn't work when I tried it with the Oculus DK2. Thanks for your help.
ublic class AutoWalk : MonoBehaviour {
private const int RIGHT_ANGLE = 90;
// This variable determinates if the player will move or not
private bool isWalking = false;
Camera head;
public float speed;
public bool walkWhenLookDown;
public double thresholdAngle;
public bool freezeYPosition;
public float yOffset;
void Start() {
head = gameObject.GetComponent<Camera>();
}
void Update()
{
// Walk when player looks below the threshold angle
if (walkWhenLookDown && !isWalking && head.transform.eulerAngles.x >= thresholdAngle && head.transform.eulerAngles.x <= RIGHT_ANGLE)
{
isWalking = true;
}
else if (walkWhenLookDown && isWalking &&
(head.transform.eulerAngles.x <= thresholdAngle ||
head.transform.eulerAngles.x >= RIGHT_ANGLE))
{
isWalking = false;
}
if (isWalking)
{
Vector3 direction = new Vector3(head.transform.forward.x, 0, head.transform.forward.z).normalized * speed * Time.deltaTime;
Quaternion rotation = Quaternion.Euler(new Vector3(0, -transform.rotation.eulerAngles.y, 0));
transform.Translate(rotation * direction);
}
if (freezeYPosition)
{
transform.position = new Vector3(transform.position.x, yOffset, transform.position.z);
}
}
}
Comment