Using the accelerometer
Another type of input that mobile has, but PC doesn’t, is the accelerometer. This allows you to move in the game by tilting the physical position of the phone. The most popular example of this is likely the movement of the player in games such as Lima Sky’s Doodle Jump and Gameloft’s Asphalt series. To do something similar, we can retrieve the acceleration of our device with the Input.acceleration
property and use it to move the player. Let’s look at the steps to do just that:
- We may want to allow our designers to set whether they want to use the
Accelerometer
mode orScreenTouch
, which we used previously. With that in mind, let’s create a newenum
with the possible values to place in thePlayerBehaviour
script above the Swipe Properties header:[Tooltip("How fast the ball moves forwards automatically")] [Range(0, 10)] public float rollSpeed = 5; public enum MobileHorizMovement { ...