In our last project, we improved our Minecraft controller code to make it simpler and more readable (and also more extensible). But, with the current code, our controller is awkward because it requires us to rotate it away from us (which is difficult to do) in order for our character to look down.

In this project, we're going to improve that — we're going to modify the tilt functionality so that our character is looking down while the controller is in the default position (horizontal or "flat on a table") and then we only need to rotate the controller towards us (which is easy) to have him look upwards.

For this project, the changes to the code will be in the while loop, specifically around the control.look() function, which defines where the character is looking.

In the previous project, we used the X and Y values of the accelerometer to control which direction we looked:

And that works... But there are two things we can improve on:

  1. Too hard to look down: To look down, you have to point the controller down, and it can be difficult to twist your wrists enough to tilt it fully down. We can adjust this.

  2. Controller is not sensitive enough: Currently, when you tilt the controller a little, Steve moves a little and when you tilt a lot, Steve moves a lot. That works reasonably well, but the current code doesn't take that far enough.

Here is what the code for this project should look like at this point (with new changes highlighted with arrows):

The above highlighted changes are:

Go ahead and give your modified controller a try...

  1. We increased the sensitivity of the controller by using x-squared instead of x. Can you increase this more by using x-cubed?

  2. The controller is now more comfortable to handle, because the default position is to keep it slightly tilted up. One issue, however, is that when you set the kit on a table, Steve will look down at the ground. Can you detect when the CREATOR Kit is placed flat on a table, and have Steve look straight ahead?