How to use Accelerometer in Unity

0 400

Learn how to use Accelerometer in Unity

Now you can easily implement motion sensing mechanism in your game using the accelerometer.

As you know that Motion sensing games are doing excellent in the market. Some of the top games include

  • Asphalt 6: is the best racing game where you get to race the car and beat the other street cars.
  • Racing Moto: It is a freestyle racing game in which you control your ride using the accelerometer.
  • Penguin skiing 3D is an Action packed 3D racing game in which you steer the penguin using acceleration.

You must be thrilled using these games and if you wish to develop your own motion-sensing game in unity then not to worry, you can add motion detection mechanism in your game using Accelerometer. First, let’s see what is an accelerometer and how does it help in motion detection mechanism.

ACCELEROMETER

Android provides different platforms that allow you to monitor the motion of a device. The accelerometer is a motion sensor which measures the orientation and tilting motion of an Android phone.

To control objects in our game we can use the device orientation. Nowadays modern Mobile phone systems have the built-in accelerometer that determines the device orientation.

ACCELEROMETER INPUT

We use Input.accleration to get input from the accelerometer.

 

  • acceleration.x & Input.acceleration.y component are used to keep the cube moving.
  • Before getting directions from Input.acceleration we’ll do some pre-processing.

I have altered the Input.acceleration code instead of using it directly, now anyone of you can use it in your game.

Comments

comments

Leave A Reply

Your email address will not be published.