Time for action – controlling the turret
This script will allow the player to rotate their turret and aim the cannon.
- The last script we need to create for our tank is
TurretControls
. This script will allow players to rotate the turret left and right and tilt the cannon up and down. As with all of the others, create it in theScripts
folder. - The first two variables we define will hold pointers to the turret and cannon pivots, the empty
GameObjects
that we created for our tank. The second set is the speed that our turret and cannon will rotate at. Finally we have some limit values. If we didn't limit how much our cannon could rotate, it would just spin around and around, passing through our tank. This isn't the most realistic behavior for a tank, ...
Get Unity Android Game Development by Example Beginner's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.