- Home /
How to move a game object by moving a device?
Hello! I'm attempting to make an Android game/application which essentially allows the user to control the movement of a game object by moving the device it's running on. So far I've been able to tilt an object by tilting the device, but I've not been able to make it move backwards and forwards, left and right etc. by physically moving the device in those directions. It's only the X and Z axis I need to function this way.
In other words, if I walked forward two steps holding the device, I would like to see the game object move forward an equivalent distance in the game environment, and so on.
Any help, advice, or links to tutorials etc. would be hugely appreciated - I'm quite new to Unity & C#!
Answer by Corentin · May 14, 2015 at 11:58 AM
I'm far from being an expert, but I think this is impossible/really hard/very imprecise. Devices don't know how much you moved on axes. Tilting is easy to measure, acceleration can be measured, but movements are much harder... you could rely on accelerometer to detect a thurst in a direction, but if the speed is constant you won't know the player is still moving, and when he stops walking you'll probably think it's going the other way (deceleration). You could really on GPS position, but this might be very imprecise too.
Hi there, thanks so much for your response - it's helped me come to the conclusion that this is definitely a bridge to far for my project! Ins$$anonymous$$d I'm going to try and just use the readings from the device's gyroscope to rotate the camera (ie 'look around') and leave the movement as an onscreen joystick. I've not had any joy with the camera rotation yet, but I'm fairly sure it can be done... wish me luck!
Answer by applemaniac · May 19, 2015 at 02:43 PM
You can't have what you need. You can only have acceleration, and you'd need to integrate it two times (accel => speed => position). This adds errors every time, every frame.
Same question and more info here : http://stackoverflow.com/questions/5068197/how-to-determine-relative-position-using-accelerometer-and-gyro-data
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
2.5D Mobile joystick rotation problem 0 Answers
My character has stopped moving 0 Answers
Mobile Movement won't work 1 Answer
Movement Object 0 Answers