Skip to content
Moritz Brückner edited this page Oct 23, 2021 · 6 revisions

Tanks Game

Let's build a mini-game! It will consist of 2 players handling a tank and battling each other. We build a small playground with obstacles and two tanks models. Each object has a rigid body set. Some of the obstacles are animated on the timeline to make the game more dynamic. The lighting setup is based on the Playground tutorial.

The red tank acts as player 1. We allow both keyboard and gamepad controls, but hard-code the actual keys for simplicity. In a Player1Controls logic tree, the left key on keyboard or gamepad is set to send an event named 'turn_left'. Later on, we use this event to rotate the player controlled tank.

Do this for all keys - left, right, forward and backward.

The blue tank acts as player 2. We define the same controls, but map the keys to WSAD and the second connected gamepad instead.

In a TankTree, we listen to the events and perform actions to actually control the tank. The reason this node tree is separate is that we attach it to both tanks, preventing duplicated node trees.

A On Event node is set to listen to the 'turn_left' event. For player 1, this event is triggered when the left key is pressed. For player 2, it happens on pressing the A key. The On Event node is connected to the Rotate Object node, with the z value of the input vector set to a small positive value controlling the rotation speed. If you play the game now, pressing the left key rotates the tank!

We do the same for the 'turn_right' event, however the vector's z value is set to a negative value to rotate in the opposite direction.

On to the handling of the 'forward' event. To figure out which direction the tank should move in, the Transform to Vector node is used, with type set to Look. The resulting vector is then scaled down using the Vector Math node to slow down the tank speed moving forward. The final vector is then passed into the Translate Object node to perform the movement.

As before, we do the same for 'backward' event with translate vector reversed.

Now that the tanks are fully controllable, we make them shoot bullets. To keep the scene tidy, the bullet object is placed in a separate collection with the Render icon disabled. This ensures that the object will be exported but not visible on its own.

Selecting the red tank, an empty object is added as a child - the location of this object defines where to shoot bullets from. A new logic tree is added to this empty object. M key or gamepad cross/a key emits a 'fire' event. We do the same for the blue tank.

We attach another logic tree for handling the response to the 'fire' event. We spawn our bullet model and set its location to the logic tree owner – in this case a bullet spawn point – defined as an empty object placed as a child of the tank.

Playing the scene now, we discover the bullets fall from the cannon down to the ground. We need some fire powder!

The Apply Impulse node fixes that. Similar to moving the tank forward, we acquire the forward vector and scale it up.

Even though Armory culls out-of-screen objects, it is important to keep used resources down to a minimum. We remove each bullet after 2 seconds of lifetime. To do this, an Array Object node is placed and all fired bullets are stored in this array using the Array Add node. We wait 2 seconds with the Sleep node and call the Remove Object node afterwards. The Array Shift node feeds the first element from bullet array into the Remove Object node, and also removes this element from array itself.

That's it - feel free to experiment further! Get the full blend for this tutorial:

Clone this wiki locally