top of page
Search
  • Kevin Chandler

We're In: Hacking Game Prototype: Part 1

Updated: Feb 24

In this part I'm going to set up the project and create several mechanics I need.


  • Keyboard based controls scheme

  • A fake "console" that prints out random lines of code as you type to make it seem like are actually hacking

  • The ability to execute special commands


Keyboard Controls

Design

What I am attempting to create is an input scheme where the center of the keyboard is like the center of an analog stick. Going out from the center the keys apply inputs in different magnitudes between -1 and 1. For example, pressing K would apply .75 input on the horizontal axis and a Q would be -1 on the horizontal and 1 on the vertical.




The movement speed would be determined by how fast you are hitting the keys and there would be a punishment for pressing the same keys more then once in a given period to discourage single key spamming.


You might asking how this works in practice. The dominant strategy as a player is to type furiously on the keyboard to get up to speed and by balancing the typing with your right or left hand in aggregate the inputs will cancel each other out, moving the player in a relatively straight line.

To turn, you would lighten up typing on the opposite side of the keyboard, same for moving up and down. So to move to the left I would ease up on the typing rate for my right hand and increase it on my left.


Implementation

So the best practice in Unreal for getting inputs from mouse, keyboard and controllers is to go to the settings and set up inputs. Since I'm using most of the buttons on the keyboard, having to create input events with 10 to 20 key inputs associated with them seemed a little hard to track and manage. Instead I am using the event "Any Key" then grabbing the key struct for what's been pressed, then comparing that against a map. The keys are all... well... keys, and the values are Vector2D's with x being horizontal input and y being vertical.



This setup allows me to tune the amount of input for each key. I also put in a global yaw magnitude modifier if I want to tune them all up or down at the same time. So from here I am going to translate those inputs into movement inputs for my character. I'm adding and subtracting from two float values, yaw and elevation based on the keystrokes, then on tick I'm adding movement inputs to the character.



At the same time every keystroke is being added to an array of keystrokes. It is also checking if your current array of keystrokes already has that key and if so it removes both entries from the array. This is the punishment for not having variety in your keystrokes, as the size of this array controls how much forward input the character is given.



On tick is where we apply movement inputs based on yaw and elevation. As a note here I'm saying elevation instead of pitch because I don't want the rotation of the character to change, just its height in the world. The camera view I'm having to use for this project means that the viewing area is narrow so pitch makes it impossible to see much of anything.



It steers like a dairy cow so some tuning is required, but it works.


Console

Design

To mimic the trope that keypresses have no relation to what's going on on the screen, I wanted to put in a dos style console that would fill with text as you type and spit out text lines that look like they could be from a hacker movie.


Implementation

For my widget setup, I'm using a scrollbox and vertical box. I have a user widget called WB_ConoleLine which is just a line of text with an event that will add a character when ever the event is called. The WB_Console will add console lines to the vertical box and because it is a vertical box it will always add new widgets to the bottom and I can tell the scroll box to scroll to the end of the list, giving it the appearance of lines continually being added to the console just like in a text interface



The first thing I wanted to do in my blueprints was figure out how to get my hacker code lines from text file so I'm not having to enter things into a datatable or field in the project and so I can add things to my list later more easily. I found a random list of hacker commands online. @echo off,

color a,

title HACK THE PLANET,

echo Scan the network? Y/N,

PAUSE >nul,

arp -a,

ping -n 10 8.8.4.4,

echo Secure connection available. Hack into computer and download all files? Y/N,

PAUSE >nul,

echo Hacking into system... please wait…,

timeout /t 5 >nul,

echo Successfully connected to system. Downloading all files... this may take a while.,

timeout /t 5 >nul,

dir /s "C:\Program Files",

echo All files downloaded and decrypted.,

echo Cover your tracks? Y/N,

PAUSE >nul,

echo Deleting hack history...,

timeout /t 5 >nul,

cls,

echo Press X to disconnect from the hacked system.,

PAUSE >nul,


I then made a text file and put it in the project folder and using a free plugin from the Unreal Marketplace called Read and Write Text. With this I can grab the text as one long string.

I put a comma after each line so I can parse the string into an array using a comma is a delimiter. Then I grab a random line from the array and set the string variable in the console line.


As keys are pressed the console line adds characters from that string to a text widget


It works like a treat, though it does not account for the same line being added twice in a row since it gets the line completely at random


Execute Commands

Design


I thought it might be fun to trigger special abilities by bringing up a console where you type in commands from a list on the left hand corner of the HUD. A mistyped command damages your character, but successfully typing the command enacts certain effects. This creates a typing skill challenge similar to Typing of the Dead where typing the correct phrase triggers an attack. For testing I'm using the word boost but eventually I'm going to replace the word with something ridiculous like "wooshtapus" or "Cheeeeetazz".


Pressing the space bar brings up the console, blocking all other inputs, and you type in the command and press enter. A successful execute triggers the ability, but a failure causes the player to take damage or maybe lose the ability.


Implementation

The WB_Abilities widget contains a vertical box of abilities. When the the player presses enter, it checks that list of abilities and sees if the name matches the string the player has entered. It then tells the player controller if there has been a successful execution and then runs through the appropriate nodes to apply the effect.




What I'm particularly proud of is figuring out how to make a fill bar representing the ability cool down that seems to turn the text from black to white as the progress bar travels. By putting black text on top and using a canvas panel with clipping set to "clip to bounds" I can animate the scale of the panel so that it matches the progress bar filling up, making the transition appear seamless




That's it for now. Next week I'll work on things like enemies, pickups, health, death states and maybe NPC barks


I'm including the project files for this point in the project for you.








7 views0 comments

Comments


bottom of page