# Using gyro.gravity for motion, orentation doesn't change.

First off, I’m very new to Unity and game programming, so I think there must be a simple solution to my problem, but I’m just missing it.

I have a third person style camera that follows a rolling ball. The ball is a rigid body whose motion is initiated buy rigidbody.addforce. I’m using android’s gyro.gravity.x and y to get my vector3 for my force vector. This works just fine, but only in the orientation where the camera is facing forward (global 0 y rotation). When I turn the camera, the perspective changes, but the gyro vector does not rotate with the camera.

What I currently have is:

``````void FixedUpdate ()
{
//float moveHorizontal = Input.GetAxis("Horizontal");
//float moveVertical = Input.GetAxis("Vertical");
float moveHorizontal = Input.gyro.gravity.x;
float moveVertical = Input.gyro.gravity.y;
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
Quaternion direction = Quaternion.Euler (0, transform.rotation.y, 0);
movement = direction * movement;

}
``````

This code is attached to the camera, with “player” being a public variable populated by my rolling ball object. I’ve been flexing my google mucles for the last day and a half and this is most simple logical code I could come up with. Problem is, it doesn’t work. As far as I can tell, the quaternion * vector3 operation does nothing. Does anyone have any ideas, or better ideas? Thanks a ton!

And wouldn’t you know it, I figured out what I did wrong. And it was simple.

``````Quaternion direction = Quaternion.Euler (0, transform.rotation.y, 0);
``````

needs to be

``````Quaternion direction = Quaternion.Euler (0.0f, transform.eulerAngles.y, 0.0f);
``````