Time for action – steering the space ship
To steer our ship, we will need to create a single script and apply it to our ship:
To start this off, create a new script and name it
TiltSteering
.As with all of our other scripts, we will begin this one with a few variables. The first two variables control the speed with which the ship will rotate as the device is tilted. The second two are going to be used to limit the rotation of the ship. These will determine how tight a circle the player's ship can turn in.
public float horizRotateSpeed = 7f; public float vertRotateSpeed = 3f; public float horizMax = 60f; public float vertMax = 45f;
Next, we will make use of the
Update
function. We start out by creating a variable to store the ship's current rotation. Next, we have to adjust the rotation. When working with Euler rotations, Unity adjusts values to be between zero and 360. This way, the values are never negative. Anything below zero simply wraps around and starts counting down from 360; anything...