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.
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.
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.