There are several applications and games that can be controlled by tilting a device. For example, such a mechanism can be used to steer a car or to control a ball that should be located in some specific place on a board. Have you even seen such a solution? Have you wondered how it is possible and whether it is difficult to implement?
If so, this recipe will answer such questions, because here you will learn how to use an accelerometer to read G-force values along the x, y, and z axes. Such values will be used to steer a ball that can freely move on the board, of course, restricted by screen bounds. What is more, the ball should behave quite naturally, that is, it should move faster when the tilting is greater. To implement such a solution, a simple mathematical model has been implemented to calculate the next location of the ball. It takes into account not only the previous location, but also the previous horizontal and vertical speeds, as well as the...