# Inclination Sensor

Use your phone as a steering wheel to avoid the approaching traffic. Will you be the next super racer?

## What bricks and objects do you need?

Create a new program and add the following objects from the media library:

# Now add these scripts to the obstacle object:

1. Step

When your program starts set the color and size of your car.

2. Step

Pick the set Y to-brick and set a value which places the object outside of your phone’s screen. For the x-position insert the “random function” which you find under the category functions in the formula editor. Set the limits of the random function to -700 and +700. Now your obstacle is randomly placed on the horizontal axis.

3. Step

To make the obstacle move from the top to bottom you need the set velocity to-brick. Set the y-value to a random number between -500 and -1500.

4. Step

When the program starts the obstacle is placed at the top and moves with a random velocity down the screen. This only happens one time. So we need to put it on top again when it leaves the screen. Pick the when becomes true-brick and insert “position_y < -600”. You can find “position_y” in the object category and “<” in the logic category while in the formula editor. So if your obstacle is outside your screen, this script starts. In this case set the obstacle to its start position again.

5. Step

Add another set velocity to-brick to make your obstacle go down the screen again. Set the y-value to a random number between -500 and -1500 so every time the obstacle has a different velocity.

# Now add these scripts to the car object:

6. Step

When your program starts you first have to change the size of your car. Then place it on the screen at a certain position.

7. Step

Add a forever loop-brick because the car needs to change it’s position all the time. Pick the change x by-brick because the car should move only on the horizontal axis. Go to the formula editor and insert “inclination_x” which you find under the category device. In order to move the car smoothly according to the phones inclination, multiply the sensor value by minus 4.

8. Step

Insert a when becomes true-brick with the condition: “touches_edge OR touches_object(Obstacle)”. You find these properties under the category object respectively in the category logic in the formula editor. At last insert two switch to looks-bricks and one wait-brick. So every time your car hits the edge or an obstacle it changes it’s look for a short period of time.

## Remix Inspirations

Ultimate steering wheel racer