What I'm trying to accomplish is keeping in-game gravity [approximately] aligned with actual gravity, regardless of camera or ImageTarget orientation. It seems like it should be a simple feature to implement -- the Input.acceleration values should give you the direction of gravity in local space, and TransformDirection() should transform the direction to world space. So far, the best I've been able to come with as far as getting the direction is:Camera.main.transform.TransformDirection ( Input.acceleration )
This is producing the wrong direction, and I'm not entirely sure why. Any insight?
After messing around with every possible combination of values, I finally found one that seems to have produced the desired effect:
Camera.main.transform.TransformDirection ( new Vector3 ( -Input.acceleration.y , Input.acceleration.x , -Input.acceleration.z ) )
I'm still not entirely sure why some of the axis had to be inverted or even swapped. I'll have to work on my 3D math skills.
@ksiva:
Since the objects are moved exclusively by gravity and not directly by accelerometer values, object motions don't appear jittery in this situation. Jitters in the Physics.gravity vector seem to average themselves out as far as their affect on object velocities. Without any tweaking, my test case of balancing a marble on an ImageTarget already seems to approximate what you'd expect to see if you were rolling an actual marble on the ImageTarget. But I imagine your input will prove very helpful as I go further into this project. Thank you very much.