- Home /
Why is the Gyroscope inverted?
Here is a script I got online, it works pretty well I just had to make a few edits, it could be a little smoother, but still. The main problem however, is that it is completely flipped. When I tilt it upwards, it moves the camera left. When I tilt it downwards, it goes right. When I move it right, it goes up, and vice versa. Tilting works correctly though. Any help would be greatly appreciated.Thanks:
// iPhone gyroscope-controlled camera demo v0.3 8/8/11
// Perry Hoberman <hoberman@bway.net>
// Directions: Attach this script to main camera.
// Note: Unity Remote does not currently support gyroscope.
private var gyroBool : boolean;
private var gyro : Gyroscope;
private var rotFix : Quaternion;
public var fpc : GameObject;
function Start() {
Screen.orientation = ScreenOrientation.LandscapeLeft;
var originalParent = transform.parent; // check if this transform has a parent
var camParent = new GameObject ("camParent"); // make a new parent
camParent.transform.position = transform.position; // move the new parent to this transform position
transform.parent = camParent.transform; // make this transform a child of the new parent
camParent.transform.parent = originalParent; // make the new parent a child of the original parent
gyroBool = Input.isGyroAvailable;
if (gyroBool) {
gyro = Input.gyro;
gyro.enabled = true;
if (Screen.orientation == ScreenOrientation.LandscapeLeft) {
camParent.transform.eulerAngles = Vector3(180,90,180);
} else if (Screen.orientation == ScreenOrientation.Portrait) {
camParent.transform.eulerAngles = Vector3(90,180,0);
}
if (Screen.orientation == ScreenOrientation.LandscapeLeft) {
rotFix = Quaternion(0,0,0.7071,0.7071);
} else if (Screen.orientation == ScreenOrientation.Portrait) {
rotFix = Quaternion(0,0,1,0);
}
} else {
print("NO GYRO");
}
}
function Update () {
if (gyroBool) {
var camRot : Quaternion = gyro.attitude * rotFix;
transform.localRotation = camRot;
var direction : Vector3 = camRot * Vector3.up;
direction.y = 0;
gameObject.Find("print").guiText.text = direction.ToString();
//fpc.transform.rotation = Quaternion.LookRotation(direction);
}
}
Well it depends on how you hold the device, whether you are holding it in portrait mode or in landscape mode.. The lines:
if (Screen.orientation == ScreenOrientation.LandscapeLeft) {
camParent.transform.eulerAngles = Vector3(180,90,180);
} else if (Screen.orientation == ScreenOrientation.Portrait) {
camParent.transform.eulerAngles = Vector3(90,180,0);
}
This part of the code is controlling the cameras rotation.
In your case the camera is rotated 90 degrees, try changing the Vector3 values and test the game again.
The other thing you want to look at is:
Screen.orientation = ScreenOrientation.LandscapeLeft;
You can change this to portrait mode if you need to
That didn't seem to do much, $$anonymous$$aybe I'm not getting the correct vector numbers?
Your answer
Follow this Question
Related Questions
Match Object (Main Camera) To Gyroscope Rotation Rate 1 Answer
What is the best way to steer the direction of a sphere in 3D space on an iPad? 0 Answers
3D camera relatively using gyro a la N.O.V.A. 2 0 Answers
Sensor Fusion of Accelerometer and Gyroscope 0 Answers
How do I access CoreMotion and the Android equivalent? 0 Answers