- Home /
How to tilt the gameobject based of Input.Acceleration?
Hello,
I have a cube which I would like to tilt based of the Input. Acceleration. So I have a gameobject that is falling towards negative Y under force of gravity. Hence my Input will be from X and Z plane. What I am trying to do is, I am trying to get the face of the cube parallel to the surface of the iPad.
CODE:
acceleration.x = Input.acceleration.x;
acceleration.y = Input.acceleration.y;
//To filter the jerky acceleration in the acceleration accel = Vector3.Lerp(accel, acceleration, filter * Time.deltaTime);
//Mapping accel -Y & X to game X & Y directions
dir = new Vector3(-accel.y, 0 , accel.x); //Limiting the 'dir' variable to magnitude 1; if (dir.sqrMagnitude > 1) dir.Normalize(); //EOF
So, from the above I have the vector which corresponds to the input. Could you please help me with this.
Thank you & Please.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How to create a damped harmonic oscillation? 1 Answer
How to rotate an object around the world axis but not on the local axis? 2 Answers
C# Rotate GameObjects Regardless of List Size 2 Answers
Rotate a GameObject without affecting the direction of motion? 0 Answers