- Home /
Using the accelerometer as controller on android.
Hi,
I am a designer and can program somewhat in Unity, but I'm absolutely new in programming for the mobile. I'm trying to create a FPS game using the accelerometer/gyroscope function as a controller. I looked for any tutorials on this matter, but there aren't many to almost none. What I want to do is when you are in idle position and move the phone forward on the z-axis, you will automatically walk forward when you reached a certain amount of force forward. Same goes for walking backwards. When you want to go back to idle position, you just the phone the opposite direction. So from walking, move the phone backwards to stand still and vice versa for walking back.
To look up you have to pitch and move the phone up and to look down, you have move your phone down and pitch down.
To rotate to the left with a steady speed happens if you yaw the phone to the left about 20 degrees and rotate right by yawing the phone to the right.
Anyone who could help me with this is much appreciated.
Answer by nsxdavid · Mar 18, 2013 at 05:29 AM
You can measure accelerations, not absolute positions in 3D space.
The Input class provides acceleration events and data.
Yes I understand that, but even if I move the phone forwards, the accelerometer should pick up acceleration in the z-axis right? So let's say I move the phone forward with a force of 2 g, it should be possible to say: When z-axis force is equal or higher than 2 g, walkspeed is 10.0f. You can keep on walking until you move your phone back again with a force of -2 g. It should be possible right? As long as the gravity on the y -axis doesn't change too much.
No I think misunderstand what I am saying. I am not talking about physically walking to make your character walk. Just moving your phone forward, like a nudge. I did some test with an app that registers changes in accelerations with the accelerometer. If you hold the phone in front of you with the screen facing you and the button down, you see that gravity has an effect on the y-axis; around -10g. If you nudge your phone forward in the z-axis you change see some changes, first a negative acceleration and then a positive acceleration.
Problem however if you pitch the phone it will also change acceleration in the z-axis. On the other hand there will also be changes in the y-axis. But when you nudge the phone forward, there are little changes in the y-axis.
So shouldn't it be possible to register a nudge forward as an action? And when that action is performed, automatically walk. Not for just the nudge you did, you walk. So a nudge forward is auto walk forward, a nudge back you return to idle stance.
I have read a lot of articles about it and yes I understand what it is for, because that is the intended use for it. But I am trying to think out of the box here and theoretically it should be possible to do it, albeit difficult I imagine.
Answer by unity_HXWyAuxDnZ3OHw · Sep 15, 2021 at 01:16 PM
have you found anything? i know it has been a while, but i am trying to do the same thing without success
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Smooth tilt accelerometer 1 Answer
Smooth Accelerometer tilt rotation 0 Answers