Actors creation from multiple meshes
Two types of actors (pawn) have been created:
- An actor called tank constituted of 5 meshes (tank body, track*2, turret and barrel).
- An actor called turret constituted of 3 meshes (mortar body, turret and barrel).
Note that I didn't created these meshes.
A landscape has been created with Terragen and it heightmap has been exported to Unreal. The landscape is displayed in the image below.
Code architecture and description
In total, 9 classes have been created, the name of the classes as well as their dependencies are shown in the pictures below. All these classes are used by the actor "tank" and all the classes boxed in blue are also used by the actor "turret". The code source of these C++ classes is available here. Note that Unreal implements a garbage collection system whereby it will automatically delete objects when they are no longer needed. Therefore the following classes (derived from UObjects) does not have a destructor.
Aiming component: The purpose of Aiming Component is to:
- Compute a launch velocity for a projectile to hit a specified point.
- Move barrel and turret toward the direction where player is aiming.
- Monitores the tank firing state. There is 4 different states: "isOutOfAmmo", "isReloading", "isBarrelMoving", "isReady". These states are used to determine the color of player's aiming reticule and are also used to determine when AI and player are allowed to fire.
- Fire a projectile, i.e. spawn and launch an object.
Projectile: The purpose of Projectile class is to:
- Add particle effects on projectile.
- Enable/disable particle effects, emit a radial force and apply damages when projectile hit physics objects.
- Destroy projectile after it hits a physic object.
- Apply damages when it hits actors
Barrel: The purpose of Barrel class is to provide a procedure allowing to rotate barrel (pitch axis).
Turret: The purpose of Turret class is to provide a procedure allowing to rotate turret (yaw axis).
Player Controller: The purpose of Player Controller class is to:
- Convert current player's aiming reticule position to World Space 3D direction.
- Trace a ray from player's aiming reticule against the world using a specific channel and return the first blocking hit (current target).
- Execute every frames the procedure from the Aiming Component allowing to move barrel and turret toward the current target.
AI Controller: The purpose of AI Controller class is to:
- Makes tanks controlled by AI go toward player.
- Execute every frames the procedure from the Aiming Component allowing to move barrel and turret toward player's location.
- Fire a projectile toward player's location.
Tank: The purpose of Tank class is to:
- Reduce tank health when tank is hit by a projectile.
- Monitor the tank health state. There is 4 different states: "dead", "low", "half", "high". These states are used to determine tank's health bar color.
- Send a notification to the "Player Controller" class when player's tank has no more health.
Input: "Input" is not a C++ class, therefore it has been highlighted in green and the related dependency is shown with a dotted arrow.
Movement Component: The purpose of Movement Component class is to allow AI and player to move their respective tank through a Fly-by-wire system.
Track: The purpose of Track Class is to provide a procedure allowing to apply a force on tank's tracks.
3 elements to assist the player have been added:
- An aiming reticule.
- A health bar for each tank.
- A display (right top corner) of player's ammo number.
These elements has been implemented by using the Blueprints Visual Scripting system: a complete gameplay scripting system based on the concept of using a node-based interface to create gameplay elements from within Unreal Editor. The blueprints used to implement the aiming reticule and the display of player's ammo number is shown in the screen below. This blueprint has been implemented in the Player Controller class.
The blueprint displayed below has been added in order to change the aiming reticule color dynamically according to tank's firing state. There is 4 different states: "isOutOfAmmo" (grey), "isReloading"(red), "isBarrelMoving" (yellow), "isReady"(green).
The blueprint displayed below has been used to retrieve from the "Aiming Component" class the number of remaining ammo for a tank.
A dynamic health bar has been added above each tank by adding a custom widget to the tank blueprint. Health bar color changes dynamically according to percent of health remaining for his related tank and disappear if it reach 0. The blueprints used to accomplish that are displayed below.
A main menu composed of a main background and 2 buttons has been created and implemented through a dedicated level. The blueprint used to implement it in a level as well as the blueprint used to configure the buttons are displayed below.
Camera and Tank Control
A camera rotation system has been implemented by using a spring arm and a azimuth gimbal (a pivoted support that allows the rotation of the camera about a single axis) in order to allow the horizon to stay horizontal even when the tank is tilted. The blueprint used to rotate the spring arm and the gimbal according to player mouse move is displayed below.
A Fly-by-wire control system has been added in order to allow the player to move or rotate his tank by performing only one action. Keys have also be mapped to allow the player to fire with his tank and to switch from a third person view to a first person view and invertly. The bluescript which has been used to accomplish that is displayed below.