- Home /
How can I get the movement when a mobile device moves parallel to the ground?
Hi everyone, I'm new to Unity. I want to get the speed of mobile devices moving parallel to the ground. After days of searching, I found it seemed that Unity could only get the "rotating" acceleration of a device, not "translation"?
So is there any way I can get the moving speed of a device? I hope it was my neglect to miss the script. If there's no such function, can I do it in Android and link the result back in Unity? Thanks.
How about using GPS? Note that Gyro and Accelerometer are different.
Thanks for your reply! I don't think GPS would be a good choice to me as I image I would need more accurate data in a smaller area.
Oh, yes I always got confused by the difference of gyro and accelerometer... O$$anonymous$$ I check them once again, so it's like I need accelerometer to get the acceleration of the device, and also need the gyro to get the orientation of the device? But the gravity seems a big trouble to the accelerometer reading to me, as a beginner...
I always found that the docs were a bit inaccurate with regard to Gyro and Accel. It seems that a lot of devices have a Gyro and call it an Accelerometer.
The Accel is supposed to measure changes of orientation but if you look at its data you see that it just gives constant orientation, not just changes. This is a Gyro, no? :D
To use the Accel as an actual accelerometer you may need to access its raw data.
Answer by mptp · Apr 15, 2016 at 02:27 PM
You're up against a fundamental limitation of the humble IMU (the primary motion sensor in a smartphone).
I won't go into detail, but basically you need an external reference frame when trying to extract positional data from acceleration data. This is the topic of a lot of research right now, and it's why VR headsets that track position like the Oculus Rift have external tracking cameras.
Unfortunately, what you're trying to do is impossible without using the camera on your phone to track visual features in the scene and use those as the external reference point, which is a hell of a task better suited to a lab full of computer vision experts.
Thank you! Thank you for killing this project (it's a good thing, it's mission impossible to me)!
I was holding the idea that "what people can do with VR headsets, we should be able to do it with a mobile roughly"... Now I know I was wrong and those bulky VR headsets does have them reasons. (I only play Google's Cardboard so I thought VR shouldn't be that complicated after all...) And I seriously realized how ignorant I was...
I should read more articles about VR later I think... Thank you again for letting me abort this impossible mission.
Impossible? No. Uncalibrated? Totally.
The answer? Set it up and calibrate it with real world data. This will be fine for some/most apps.
Its easy to take a step to the left, step forward etc.
So I missed your last reply. But getting the parallel movement seems really hard to me as I'm working alone and lack of professional knowledge. I imagined to track the movement of a device when the user is walking and turning. As I did found the accelerator acts like a gyro, it's very hard for me to peel the needed small variation off from those big changes coursed by tilting the device.
Oh, forgot to say, I'm bad at maths too, so the three dimensional calculating would be even harder... I would be doing both hard analysis and calculation... As this project is not that... eh... necessary, I do think the best option for me is to kill/suspend this project for now and wait for better technologies...
Thank you for giving me hope, I'll keep my $$anonymous$$d on some algorithm in this field.
it's very hard for me to peel the needed small variation off from those big changes coursed by tilting the device.
The linked method does this for you
http://docs.unity3d.com/ScriptReference/Input-accelerationEvents.html
It takes all the movements and whacks them in to an array, movement and time taken for that movement.
mptp is correct in his answer but this is dependent on the need for accuracy.
Answer by DoubleLee · May 17, 2017 at 06:32 PM
Input.gyro.userAcceration takes into account gravity and returns in a unity coordinate format m/s*s acceleration. This gets you the acceleration in theory this would be what you need but it doesn't take into account that rotations also increase the acceleration values means it's not the linear motion but linear and rotational combined. If you can use the gyro to remove the rotations you maybe able to use this. Good luck that's where I'm stuck.
I'm also attempting a similar movement controls by devices acceleration and it's very difficult. Also these values are dirty not always 0 0 0 when the phone is just sitting on the table. And the accuracy is probably not going to be correct enough for accurate movement required for a FPS style game/app.
Your answer
Follow this Question
Related Questions
Getting X axis input from accelerometer when mobile device is held upright? 4 Answers
How to judge intensity of shaking in android phones 1 Answer
Changing origin of cooridinates to decieve gyroscope in ARCore 0 Answers
Using custom accelerometer, gyro & magnetometer to move objects 1 Answer
gyro.attitude lags on Samsung Galaxy S2 0 Answers