Accelerometer & Rotation
Ok so I'm trying to make a game which uses the accelerometer and rotation to control a game object. I am having a problem with the rotation though. I'm using C# for all of my coding. First I started out by putting the value from Input.acceleration into a Vector3:
Vector3 thisRotation = new Vector3 (Input.acceleration.y * 100, 0, Input.acceleration.x * 100);
I'm attempting to keep the object from rotating in the Y axis, and my current method is actually working quite well in that regard, and I am also trying to control the object in a top down landscape view. When I put Input.acceration.x into the x, and y into the z it actually showed me that the values were not what I was expecting. That is the reason why I set up that line of code the way I did.
Inorder to get my game object to rotate I am using this line of code with thisGameObject representing the game object I want to apply the rotations to.
thisGameObject.transform.rotation = Quaternion.Slerp(thisGameObject.transform.rotation, Quaternion.Euler(thisGameObject.transform.rotation.x + thisRotation.x,
thisGameObject.transform.rotation.y + thisRotation.y, thisGameObject.transform.rotation.z + thisRotation.z), Time.fixedDeltaTime);
My problem is that the game object is rotating in the opposite direction in the X and Z axes. I have tried to change the application of the 100 modifier in the input section to a -100, and I tried multiplying the rotations by -1 in the rotating line of code. Regardless of what I do though it seems to be rotating opposite of what is the desired effect. For reference my game is locked in a right side up landscape view. Also when I tried to use the Rotate function the game object would just continue to rotate. These lines of code are happening inside of the FixedUpdate function.
Answer by Martians135 · Jun 16, 2017 at 05:09 AM
May be this asset can helps: You can use this asset to Do the rotation. You can use the accelerometer like a gyroscope , this works on all phones, because all devices have accelerometer. And works on all axes. Here this asset: