iPhone assumes scene already tipped forwards 70+ degrees?

Hi all,

I have a minor coding issue. This code, err, “shakes the monkey” correctly but regardless of the orientation/rotation of the scene objects, it immediately wobbles the monkey forward when you hold the screen at a normal viewing angle (approx 15 degrees tipped back from vertical, upright).

What do I add to tell it that laid flat down is actually 70 degree backwards and that a normal upright held position is where to assume the y orientation is 0 and then to tip forward only when the device gets tipped so that the top of the device is now straight up?

function FixedUpdate () {
		
	var accelerator : Vector3 = iPhoneInput.acceleration;

	x = accelerator.x * 15;
	y = accelerator.y * 15;

	cameraRelativeX = Camera.mainCamera.transform.TransformDirection (Vector3.right);
	cameraRelativeY = Camera.mainCamera.transform.TransformDirection (Vector3.forward);

	shake = cameraRelativeX * x + cameraRelativeY * y;
	
	bodies = FindSceneObjectsOfType (Rigidbody);
	for (var body : Rigidbody in bodies)
	{
		body.AddForce (shake);
	}

}

This is sort of what I’m attempting …

function FixedUpdate () {
		
	var accelerator : Vector3 = iPhoneInput.acceleration;

	x = accelerator.x * 15;
	y = accelerator.y * 15;

	cameraRelativeX = Camera.mainCamera.transform.TransformDirection (Vector3.right);
	cameraRelativeY = Camera.mainCamera.transform.TransformDirection (Vector3.forward);

	shake = cameraRelativeX * x + cameraRelativeY * y (-70degrees);
	
	bodies = FindSceneObjectsOfType (Rigidbody);
	for (var body : Rigidbody in bodies)
	{
		body.AddForce (shake);
	}

}

Does it somehow involve iPhoneOrientation.FaceUp?

Thanks!

Can’t you just set things to be kinematic (or whatever) until everything is initialized? I realize this is a workaround rather than a fix, but Unity has a lot of bad behavior across load transitions :-/ (Hey – Director has lots of bad behavior across frame redraws… so I’m not complaining.)

I’m also having a problem with this. Can anyone assist?

I guess you would need to define your own “0 direction” and then work with differences to that 0 direction.

http://blog.digitalagua.com/2008/07/15/accelerometer-xyz-based-on-iphone-position/

This is a helpful page to get your head around the values the accelerometer gives off.

Oops! This is the link I meant to give you:
http://blog.digitalagua.com/2008/07/15/accelerometer-xyz-based-on-iphone-position/

They’re both useful, but the second one is far more clear!