Friday, 19 October 2018

Game - Developing the static targets


In my game, I was planning on adding static turrets (or targets), which could be destroyed when the player shoots them. The turrets would also rotate to face the player at all times. This blog post will mention Blueprint actions. The turret component was created from a basic cylinder class in Unreal, from the Nodes tab.

The final static turret, after the Blueprint development.

How I set up the blueprint:

I used two blueprint classes. One class is attached to the player, and a second class is attached to the turret.

In the First Person Character blueprint:
Firstly, the player can shoot at opposing targets using the LineTraceByChannel Blueprint action, with the result of the line trace coming from a Break Hit Result action. The 'hit component' from the Break Hit Result would be checked to see if it has a Component Tag called 'Shootable'. If true, apply 150 damage.

Click to enlarge the image. This shows a section of the First Person Character blueprint, in relation to accessing an object through the Component Tag.

In the StaticTurret blueprint:
An AnyDamage Event is used to see if any damage has been done. If so, it will destroy the actor.

An Event Tick event is ran on every frame, and is used to rotate the turrets.  The FindLookAtRotation action is called to set the new world rotation, based on the player's location (GetPlayerCharacter -> GetActorLocation) and the self location (Static Mesh Component -> GetWorldLocation).

I chose to split up this vector, to keep the component on a 90* y-axis angle, and only rotate the object left-right in the 3D space.

Click to enlarge the image. This shows the Blueprint class that allows the static turret to receive damage (Event AnyDamage) and rotate on the X/Z axis towards the player.

Conclusion
In this section, I have learned that Unreal chooses to use two different tagging methods. There is the Component Tag, used to add a string to access components, while there is an Actor Tag used to add a string to access actors.

In comparison to Unity, I discovered this to be relatively challenging at first, because I struggled to understand the difference between Actors and Component classes (in Unreal). In Unity, there is only one tag mechanic which I see as much easier to learn and use, while Unreal extends this approach - which can be useful to control only specific classes and use similar tag names. Both applications allow the user to store multiple 'tags', but Unreal separates these to base them on Actor/Component classes.

Both Unity and Unreal also share the ability to run actions on every frame. Unreal has the 'Event Tick' action, while Unity has the 'Update()' script method.