First things first: Get some graphics
Importing the assets into Unity is super easy: Just drag them and drop ’em into Unity. It took me about two minutes to build a very little and simplistic tank like this one:
The first TankZ tank. Cool, eh? ;-)
Player Tank GameObjects
This is done by stacking some GameObjects with two textures. It’s stacked this way (as shown in the screenshot on the left), so we can manipulate them better later, when the barrel will follow the mouse. How this is done, will be explained in the next blog post.
Components “tankBeige_outline”
The “tankBeige_outline” (oh yes, I just was way to lazy to rename the original asset…) is made of a Sprite Renderer with default values and a Box Collider 2D, so we have easy collision detection later on. The same settings are used for the barrel, expect it’s missing a Box Collider 2D. I don’t feel it’s necessary that the barrel can collide with other things. The base of the tank should be fine for that.
GameObjects “PlayerTank”
At last, the GameObject “PlayerTank” got a RigidBody 2D attached. It is used for moving the tank later with the WSAD keys. Please note, that I’ve modified the values for Mass, Linear Drag and Angular Drag. It’ll lead to a bit more realistic movement of the tank.
The next blog post will explain, how the barrel will follow the mouse and the tank is moved. Stay tuned!
In the meantime: Don’t forget to take a look at the current source code at GitHub and the example deployment.