- Home /
Cos creates problems with addforce
Hello,
So I am making a 3d game on android and using the accelerometer to move. When I play the game on the phone, it is very hard to control my character because I have to hold my android at 90 degrees for no force. I tried the following code so that the user can have a comfortable angle of holding and playing while sitting. But when i use Mathf.Cos/System.Math.Cos for creating and adding force, my camera goes to some weird location when i tilt my phone parallel to the ground. If i use some other value for the variable, it doesn't create the problem. I have been trying for hours to figure this out and have had no luck. Is it possible to do so in another way? Could it be a possible bug?
I'm using Unity 5.1.2f1 Express Edition.
Thanks.
I tried with the following code:
float moveVertical = Mathf.Cos ( Mathf.Acos((float)-Input.acceleration.z) - 1.3f );
float moveHorizontal = Input.acceleration.x;
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
gameObject.AddForce (movement * speed);
Your answer
Follow this Question
Related Questions
Using sin and cos to decompose a vector 2 Answers
What's wrong with this algorithm? 2 Answers
Unity3d how to make cos 90 equal to 0? 1 Answer
radiusX and radiusY ? 1 Answer