Need Help with Accelerometer

Hello all,

i am creating a game having character movement in the space.
i had done all the movement and tilt using joystick,but can’t find the way out to get the exact movement using accelerometer.

my game mode is landscape.

any suggestion/code will be very helpful.

Thanks in advance!
Niki.j

make that as a reference and try .I think u can do that .

i am using the joystick script available in the standard assets for getting the input from the joystick.
that script provide me the movement input,and also restrict the character/Rigidbody to its minimum and maximum movement.

i know about the Input.Acceleration. and i am using the same in my code.
but can’t find the way to give the exact movement.

Thanks,
Niki.j

What exactly do you mean with exact movement ?

The accelerometer always returns values relative to the default position. If you plan to hold the device at an angle, make sure to substract this from the accelerometer values.

If you want to know the difference between the values of this frame and the values of last frame, you’ll have to save the values for a frame to substract from the values of the next one.

using input.acceleration it will provide me the movement,but what i get is:

  1. only on maximum tilt it will provides me the input and moves the character on Left/Right/Up/Down.
  2. after some time it will start rotating itself in x-axis.

actually i want to play the animation for my rigid body according to the input from the accelerometer.
and want to restrict the input from minimum value to maximum.thats the exact problem that i am facing with the accelerometer movement.

Thanks
Niki.j

Sorry for the late reply.
In case you haven’t solved the problem allready :

  1. Debug.Log the accelerometer values and see if they vary depending on tilt. They are floats, so if you use them as ints somewhere, they will get rounded which could cause the problem you have.
  2. Not realy sure what could cause this. A piece of code could be helpfull.

Restricting input can be done using the Mathf.min and Mathf.max functions.

Hello mark,

sorry for the late reply also thanks for the suggestions,
i am using for getting input from joystick,

i am tying to convert the same for getting the input using accelerometer.

anything would be very much helpful

Thanks in Advance!
Niki.j

1162582–49102–$Accelerometer_Movement(Star Kids).js (75.4 KB)