W
W
WHOAMI2018-04-17 15:53:29
C++ / C#
WHOAMI, 2018-04-17 15:53:29

Why might Input.acceleration not work?

Good day!
I need to get a Vector3 through the accelerometer (Input.acceleration) to rotate a 3D Object.
I tried to get it in this way:
Vector3 pos = Input.acceleration;
But no matter how I moved the phone, nothing changed...
I tried to get Vector3 via Input.mousePosition, everything worked out!
! ̶I̶z̶ ̶e̶t̶o̶g̶o̶ ̶s̶l̶e̶d̶u̶e̶t̶ ̶t̶o̶, ̶ ̶ch̶t̶o̶ ̶o̶sh̶i̶b̶k̶a̶ ̶n̶e̶ ̶v̶ ̶k̶o̶d̶e̶ ̶ check
if there is a resolution to Edit -> Project Settings -> Player :But did not find anything: /
check whether all the accelerometer in your phone - there ...
I checked that foreign forums - Found nothing (Maybe I was looking badly).
What could be the problem? (Unity 2018.1.0b12; SDK and JDK present!)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WHOAMI, 2018-04-18
@1010111100100010011111000

5ad6d3f4ca23d464356652.gif
My inattention played a cruel joke on me... The code that I did was first sharpened for mousePointer. And in order to normalize the rotation behavior, I found out half of the width and length of the user's screen:

float halfWidth = Screen.width * 0.5f;
        float halfHeight = Screen.height * 0.5f;

Later, I subtracted this value from the desired axis of the mouse cursor position and divided everything by the same value that I received earlier:
float x = Mathf.Clamp((pos.x - halfWidth) / halfWidth, -1f, 1f);
    float y = Mathf.Clamp((pos.y - halfHeight) / halfHeight, -1f, 1f);

And because of this, the behavior of the accelerometer was incomprehensible (It felt like it was not working), but in fact it worked, I debugged the current position, and it changed ...
Sorry for such a stupid question, just practicing on mobile platforms for the first time, and I forgot that I did everything under my arm ಠ_ಠ
Thank you all!

G
GavriKos, 2018-04-17
@GavriKos

Acceleration just to shove into a position is a fig idea.
We would have tried it already as in off. example:
https://docs.unity3d.com/ScriptReference/Input-acc...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question