Making the Game: The Shockwave Gun
As I talked about in my previous post, the main mechanic in Robotrooper: Simulation involves a shockwave gun which can push things around. In this blog post, I will detail the process of its creation.
The Process
To begin implementing this, I added a new action mapping to the project called "Swap". I did this by going into the Project Settings editor from the Edit menu and finding the Input section under the Engine category. The process of setting up a new mapping is actually quite similar to how it is in Unity, although I think Unreal's Input settings are a bit more intuitive out of the box. I mapped "Swap" to the Left Shift key. This means that when the Left Shift key is pressed, whatever actions I assign to "Swap" will be fired.
Anyway, after doing that, I used this new mapping to create a "swap gun mode" functionality for the gun using Blueprints Visual Scripting, added to the FirstPersonCharacter blueprint. This uses a simple Branch node (basically an "if statement" in conventional programming) coupled with a Boolean variable which changes based on the current Boolean value.
Once that was done, I was ready to add the actual shockwave functionality. I quickly realised that having the gun shoot just one type of shockwave would be boring and possibly very overpowered depending on its power, so I decided to have a timer which would determine the power of the shockwave based on how long the "Fire" mapping was held for.
Once "Fire" is let go, the value of "Charge" is used to determine the strength of the shockwave. I decided to limit this shockwave to three types. Using a few Branch nodes, a "Launch Force" integer is set and the player character is launched in the opposite direction of the camera's current viewpoint using the aforementioned integer. I did this using the Get Player Camera Manager node, which gets a reference to the player camera. The Get Actor Forward Vector node then gets me its forward vector, i.e. the direction the camera is currently facing. I negate this forward vector by use of the Negate Vector node. After multiplication with the "Launch Force", it is fed to the Launch Character node.
An invisible projectile is also fired in front of the player, using the same "Launch Force" integer. Whatever it hits will be sent flying using that very same force, simulating a shockwave of sorts.
Functionally, the shockwave gun was done at this point. However, there was no indicator of how long the "Fire" mapping's been held or indeed the strength of the shockwave that would be fired. For this I created a new HUD widget (the equivalent of the Canvas in Unity) with a simple text component and a progress bar. The progress bar was bound to a get percent function (pictured above) which gets the current "Charge" and divides it by 3.
The Result
Overall, I am satisfied with the way the gun works. It performs its functionality just as I had described it in my original proposal for the project, i.e. it launches things, including the player.






Comments
Post a Comment