Making the Game: Environment Scanner

A bit earlier than my usual posts, but I have just finished a feature I am quite proud of - the Environment Scanner! It's inclusion isn't necessary to the completion of the core game mechanics, but it is something I wanted to do back in Foundation Year. Sadly, I didn't get the time to implement it back then.

Functionality


So what is it and what does it do? Whenever Robotrooper looks at an object within the game. he gets the option to "analyze" it.


After doing so, the object's name and a short description of it appears on screen. This can serve as a hint if the player is ever unsure about what to do next.

Implementation

The Descriptor


To implement this, I wanted to quickly add common functionality to all objects that could be "scanned". At first I tried doing this by reparenting the objects to a "Descriptor" parent object, but this had weird unintended side-effects, mostly to do with the root of the object changing.

In the end, I ended up creating the "Descriptor" as a Component Actor, or Component. These serve as sub-objects within other actors, ideal for what I was trying to do. Anyway, my "Descriptor" holds the following information in the form of variables:



Once the "Descriptor" was done, I attached it to the Cube Key and the Cube Slot Button and added individual descriptions to both of them.

The Scanner Itself


Firstly, I created new Input Action mappings called Analyze and Environment Scanner Toggle.* Analyze is used to analyze the object of course, and the Toggle is for turning the Scanner on or off. I imagine once a player knows what an object is, it could be quite annoying to still keep seeing the information.


Then, I began building the functionality itself. First I added a Branch that checks whether the scanner is on or not to the FirstPersonCharacter's Event Tick. If the scanner is determined to be on, a raycast is fired 2000 units in front of the player from his current viewpoint. This is done using the LineTraceByChannel node, and yes, it works just like a raycast does in Unity! The values fed into it come from the First Person Camera component.


Admittedly, the wires get really crazy as the nodes go on, so I do apologise for that! I was very exited to get the scanner finished. I will have to properly untagle them later. 

Anyhow, I dragged out the Out Hit from the raycast and broke it down using the Break Hit Result node. This allows for extracting all kinds of information about what was hit. The important bit for me was the Hit Actor of course. First, I check that an actor was indeed hit. Afterwards, I check if the actor has a descriptor. If not, nothing is displayed, if it does, another check is performed, etc.


As you can see above, many more checks are performed by Branches. Based on the outcomes, different information will be displayed by the Environment Scanner. This is done by setting new Text variables on the FirstPersonCharacter Blueprint. These are then bound to text widgets added to the HUD widget blueprint, where they will be displayed to the player.


One of the options allows for pressing the Analyze Input Mapping to analyze the object in the first place. This sets the Analyzing boolean to true, sets the "Last Scanned" actor variable to be the Hit Actor. This is followed by a Delay node, to give the illusion of the object actually being analyzed. Once done, all actors of the Hit Actor's class are looped through using a ForEachLoop node and their Descriptor's "Analyzed" variable is set to true, meaning they will now be displaying their full text to the player.

And there you have it, that's how the Environment Scanner works. I am very pleased with how it turned out!

*You may have noticed that the "Swap" mapping from the Shockwave Gun blogpost is now gone. This is because I have completely removed the original FPS template gun functionality.

Comments

Popular posts from this blog

Making the Game: A Simple Puzzle

How to Keep Blueprints (Mostly) Readable

Making the Game: Final Touches