1

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.

ramayac
  • 5,173
  • 10
  • 50
  • 58
Jean Allen
  • 63
  • 3
  • 14
  • But you do exactly this with the accelerometer. You can also try the gyroscope. It is actually extremely straightforward - one line of code. please google as there are thousands of examples around. – Fattie May 24 '16 at 19:20
  • no one have any idea? – Jean Allen May 24 '16 at 19:20
  • It's absolutely impossible to know *absolutely* the exact point in space of the device - of course. If you're thinking of something like that just forget it and do something else. – Fattie May 24 '16 at 19:20
  • I'm voting to close this question as off-topic because extremely easy to google 100s of pages on this one. – Fattie May 24 '16 at 19:21
  • accelerometer gives TILT,sorry misstyped...the tilt of the device with the hand,but imagine i got the device in my hand and i am just walking.....walking forward....i want the unity object do the same...i do not rotate the device,do not tilt it just holding in my hand going forward...in that case accelerometer wont help – Jean Allen May 24 '16 at 19:21
  • Click the EDIT button under your question, correct the typos. Also make sure that after each "." full-stop you have a space, thanks. – Fattie May 24 '16 at 19:22
  • correct if you are WALKING forward, **it cannot be done**. you did not say that in your question. if you mean holding it in your hands and MOVING it forward/backwards, you will find the accel'r works great. You could have tried it 100 times over the amount of time spent on this QA :) – Fattie May 24 '16 at 19:23

1 Answers1

1

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

Basile Perrenoud
  • 4,039
  • 3
  • 29
  • 52