Calculating linear acceleration of a phone on Android


I’m creating a game for Android where the movement of certain objects is dependent on how fast the person is travelling (such as when they are on a train).
So essentially: I need to create a speedometer which I can use to affect different objects in the game.

I’ve never worked with sensor input before: and was wondering if anyone had any pointers as to the best method to go about this?

Should I calculate the speed using the GPS (this would have issues when on the tube/subway but not the end of the world)

Or should I calculate it using the accelerometer?
I can’t work out if I would be able to use the input.acceleration to create a speedometer, or if this would have issues when the phone is rotated.

Sorry this question isn’t more specific - I’ve been trying to get this working in Android Studio, but I’m looking now to see if I would be able to do this inside Unity.

If anyone has any ideas or pointers that would be so helpful!

All the best,

@laurienvictoria Although this reply doesn’t answer the question you asked, It should be of some help in your process of elimination, because the accelerometer is calculated by the pan, tilt, roll of your phone, not the speed you move (Or at least I’m pretty sure)

I think your first Idea is the way to go, using