- Home /
Vector 3 and Acceleration Issue
Hi, I have a set of code that rotates my camera based on "Acceleration" (working on Android). It works fine except my camera starts off straight down. I can't figure out how to start the camera looking straight.
Basically I'm trying to get the head movement to start off looking straight and have a up/down and left/right motion.
Any suggestions?
[Range(0, 355)]
public float minAngle = 50f;
[Range(0, 355)]
public float maxAngle = 310f;
void Update ()
{
transform.Rotate(Vector3.right * Input.acceleration.y * 2.0f);
if (transform.eulerAngles.x >= minAngle && transform.eulerAngles.x <= (minAngle))
transform.eulerAngles = new Vector3(0f, 0f, minAngle);
if (transform.eulerAngles.x <= maxAngle && transform.eulerAngles.x >= (maxAngle))
transform.eulerAngles = new Vector3(0f, 0f, maxAngle);
transform.Rotate(Vector3.down * Input.acceleration.x * 2.0f);
if (transform.eulerAngles.z >= minAngle && transform.eulerAngles.z <= (minAngle))
transform.eulerAngles = new Vector3(0f, 0f, minAngle);
if (transform.eulerAngles.z <= maxAngle && transform.eulerAngles.z >= (maxAngle))
transform.eulerAngles = new Vector3(0f, 0f, maxAngle);
}
The Transform for the camera's Rotation is set to 0,0,0. It is a child of a Parent object called "Fist Person Controller". The FPC's Rotation is also 0,0,0. Should I adjust any of these start rotations?
This video shows exactly what Im trying to do, but with an Android, which is why I can't use the gyroscope code: http://youtu.be/sjwy3oGPu6Y
Your answer
Follow this Question
Related Questions
acceleration and eulerAngle problem 0 Answers
Frame Independent Movement with AddRelativeForce 1 Answer
Android Z Axis 0 Answers
Get absolute acceleration data from accelerometer/gyroscope but neglect rotational acceleration 1 Answer
Accelerator.x rotating camera.z - problems with intermediate values 0 Answers