- Home /
Rolling a sphere relative to Camera rotation
I'm working on a new control scheme for the Oculus Rift that utilizes the tilt of the headset to move the player. Meaning, you tilt your head back and forth to go forwards and backwards, and from side to side to strafe. The camera is tied to a rolling sphere, as that gave it a nice sense of acceleration, and feels a bit like kind of flying around. So far, it's working quite well, but only on the global axis. So if you turn to the left and tilt your head forward, you still go forward according to the starting position (Which if you're facing to the left means you'll go right). I'm trying to fix it so that you can go forward and strafe relative to the direction the camera is facing, but with no luck. I have a strong sense that it's something ridiculously simple, but I just can't seem to find it. Any help is very much appreciated!
Here is what I have on the rolling sphere right now:
public GameObject RightCamera;
void FixedUpdate(){
float angleX = RightCamera.transform.eulerAngles.x;
angleX = (angleX > 180) ? angleX - 360 : angleX;
float angleZ = RightCamera.transform.eulerAngles.z;
angleZ = (angleZ > 180) ? angleZ - 360 : angleZ;
Vector3 movement = new Vector3 (-angleZ, 0, angleX);
GetComponent<Rigidbody>().AddForce (movement);
}