DESIGN
Tanks (working title) is a school Unity project I created back in 2017. The goal is to create a tank game using Unity’s terrain system and particle system, and also include enemy AI. At that time I was just starting to learn the basics of 3D modeling (which I still am now) and Unity’s Post-Processing Stack. After playing with some free-to-use assets, I sticked to Low Poly Nature Pack Lite to build the scene.
In the end I thought the winter settings and the minimalism suits this game really well. Finally I modeled my own tanks in Maya to fit this melancholy atmosphere.
PROGRAMMING
Player Movements
I created my own tank controller by scratch, both player movements and enemy AI. Both of them shared the same movement techniques — if a tank moves, the front of the tank must be facing, or at least is rotating to face, its forward direction. Hence the simple transform.Translate
method will not work. The end result is to implement a custom SetMovement
method, in which two perpendicular vectors are fetched each frame: the forward vector and the right vector. The following code excerption and comments show the abstract outline.
Bullet
All enemy tanks and bullets are instantiated from their prefabs. When a bullet hit a tank, it will call different methods depending on the tank it hit, and is irrelevant to the tank who fired it: If it hits the player, it resets the player to the previous checkpoint and reduce one health; if it hits the enemy, the enemy tank is destroyed and the score is added to the player.
Enemy Movements
Enemy tanks have a basic moving principle similar to the player, but they are driven by a state machine rather than user inputs. The states and the ways an enemy tank work are as follows:
- Chase: In this state, the enemy starts to chase the player in a higher speed than patrolling. The enemy now glows in red and the background music changes depending on the context as well. If the player escape its detection range, the enemy will give up and return to its patrolling state.
- Patrol: The enemy tank will start to chase after the player, if it get closer to a certain range, the enemy will enter shooting state and start to shoot.
- Shoot: If the player gets even closer to the enemy tank, the enemy will start to shoot at the player.
SOUNDS
Theme music and sounds for this project are created by myself.