Time for action – controlling the chassis
A normal tank rotates in place, and it can easily move forward and back. We will make our tank do this with the creation of a single script.
The second script is called
ChassisControls
. It will make our tank move around. Create it in theScripts
folder as well.The first three lines of the script define the variables the tank will need to move around. We will also be able to change them in the Inspector window, in case our tank is too fast or too slow. The first line defines a variable that holds a connection to a
CharacterController
component. This component will easily move the tank around, but will allow it to be stopped by walls and other colliders. The next two lines of code define how fast we move and rotate:public CharacterController characterControl; public float moveSpeed = 10f; public float rotateSpeed = 45f;
Now let's add our good friend
OnGUI
to the mix. This should look mostly familiar. We are creating four buttons that will sit in the...