Jean Allen
Jean Allen

Reputation: 63

Unity C# device movement direction capture

Good day.

I want to make an app which is somewhat very close to the device movement.

In example: If the device moves backward, the unity 3D object should move backward, if forward then the object goes forward in 3D environment, then same and for left and right.

Anyway the workaround i have googled only brought me to accelerometer, which I don't need, as accelerometer is used to detect the tilt and not actual movement. So i wanted to ask, is that even possible to detect the movement of device in unity? If yes, what classes should i look for to achieve what i want.

Thank you beforehand.

Upvotes: 1

Views: 1978

Answers (1)

Basile Perrenoud
Basile Perrenoud

Reputation: 4112

Jow Blow's comment is correct: The accelerometer gives the acceleration (you don't say). Tilt can be found from the amount of acceleration, but other movements will be seen as well. If you are standing still and start moving forward, your accelerometer value will show it (since you accelerated).

There is no device that will measure if you are moving forward at constant speed on your phone. If you know a bit of physics you find more obvious why the accelerometer doesn't work: because constant speed means that the resultant of forces is null. So there is no force to detect.

If you need to detect constant speed and plan to move for a rather big distance, however, you could try using the GPS position but if you need a high precision, you won't be able to do it with a standard device.

Forget about detecting moving at constant speed on a short distance easily. A solution could be to detect an acceleration and estimate the direction and speed resulting from it (speed = time*acceleration). This method won't be really precise as any error will add up but it could be sufficiant

Upvotes: 1

Related Questions