The script that I was using to control the camera with my iphone’s gyroscope seems to have broken when upgrading to 4.5. It works perfectly when testing with unity remote 4 but does not load up when pushed from xcode despite no errors or warnings. Any Insight?
I originally found the script here. http://forum.unity3d.com/threads/sharing-gyroscope-controlled-camera-on-iphone-4.98828/page-2
// 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;
function Start() {
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 = SystemInfo.supportsGyroscope;
if (gyroBool) {
gyro = Input.gyro;
gyro.enabled = true;
if (Screen.orientation == ScreenOrientation.LandscapeLeft) {
camParent.transform.eulerAngles = Vector3(90,90,0);
} 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);
}
//Screen.sleepTimeout = 0;
} else {
print("NO GYRO");
}
}
function Update () {
if (gyroBool) {
var camRot : Quaternion = gyro.attitude * rotFix;
transform.localRotation = camRot;
I got it working using this script. `#pragma strict
static var gyroBool : boolean;
private var gyro : Gyroscope;
private var quatMult : Quaternion;
private var quatMap : Quaternion;
private var camGrandparent : GameObject;
function Awake() {
// find the current parent of the camera’s transform
var currentParent : Transform = transform.parent;
// instantiate a new transform
var camParent : GameObject = new GameObject(“camParent”);
// match the transform to the camera position
camParent.transform.position = transform.position;
// make the new transform the parent of the camera transform
transform.parent = camParent.transform;
// Also creates a grandparent (camGrandparent) which can be rotated with localEulerAngles.y
// This node allows an arbitrary heading to be added to the gyroscope reading
// so that the virtual camera can be facing any direction in the scene, no matter what the phone's heading
camGrandparent = new GameObject("camGrandParent");
// match the transform to the camera position
camGrandparent.transform.position = transform.position;
// make the new transform the parent of the camera transform
camParent.transform.parent = camGrandparent.transform;
// make the original parent the grandparent of the camera transform
camGrandparent.transform.parent = currentParent;
// check whether device supports gyroscope
gyroBool = SystemInfo.supportsGyroscope;
if (gyroBool) {
gyro = Input.gyro;
gyro.enabled = true;
#if UNITY_IPHONE
camParent.transform.eulerAngles = Vector3(90, 90, 0);
quatMult = Quaternion(0, 0, 1, 0);
#endif
Screen.sleepTimeout = SleepTimeout.NeverSleep;
} else {
print("NO GYRO");
}
}
function Start() {
// First, check if user has location service enabled
if (!Input.location.isEnabledByUser)
return;
// Start service before querying location
Input.location.Start();
Input.compass.enabled = true;
// Wait until service initializes
var maxWait : int = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) {
yield WaitForSeconds(1);
maxWait--;
}
if (maxWait < 1) {
// Service didn't initialize in 20 seconds
print("Timed out");
return;
}
if (Input.location.status == LocationServiceStatus.Failed) {
// Connection has failed
print("Unable to determine device location");
return;
}
}
function Update() {
if (gyroBool) { #if UNITY_IPHONE
quatMap = gyro.attitude; #endif