Vikings Fury is a co-op brawler created using C++ in the Unreal Engine. It was a 10 day solo project for me with the goal of gaining a good understanding of C++ as a language and how it is used in Unreal.
The game has support for 2-4 players where the goal is to shoot down your opponents using fireballs. The game is heavily based on momentum and physics, shots has an intense pushback effect that can be used to traverse the map and quickly reposition yourself for a takedown of your opponent.
Unreal Engine 4.17
This 10-day project was made to increase my knowledge of the C++ programming language. Having had almost no knowledge when I started the project(What's a header?), I found myself spending the first few days
doing a lot of reading and studying of the basic concepts and syntax of the language as it's quite different and a lot more low level than C#. The biggest challenges I had throughout the project was pointers, not just understanding them but also applying them in practice. But after the first three days of studying, the development went very smooth.
During the development process I also found myself learning a lot more about how visual studio and how IntelliSense is completely broken when paired with Unreal and C++! Good thing there is Visual Assist for that. When debugging I often found myself building the solution in visual studio and checking for null pointers when exceptions where thrown, pointers that I started to understand a lot more once I actually got to use and debug them. Learning by doing!
Main Player Pawn
Every single single class was first made in blueprints for testing and then ported in to C++ step by step. However in C++ I felt like I could structure the system a lot more. I wanted to keep the tick as short and concise as possible and split up the main functionalities into functions for improved modularity. While I at first thought that the header file was distracting as I had to switch between editing two files, I later on felt like it was a great tool to help me organize variables and functions and keep the main .cpp file less cluttered. While reading up on the coding standards for both Unreal and the language itself, I noticed that even commenting was more efficient and tidy as I could explain most variables and function in the header file.
In the tick function I keep track of rotation of the arrows and movement. I use the unreals axis functionality to keep track of when to fire. When the right trigger is pressed I spawn the arrow that starts charging along with a bomb. When the trigger is released I despawn the arrow and fire away the bomb with a force depending on how long the trigger was held. Spawning bombs and arrow in realtime taught me very quickly that it's important to check for null pointers and handle them properly as not doing so can lead to very unexpected results.
With the focus I had of having my variables editable in the editor, I made one class for all the buffs and then have the game randomize which buff to spawns via an enumerator. A base buff was created where you can change the core variables such as meshes, materials and particles. Then in the code I wrote the logic of each buff that changed depending on the variable of the enumerator.
The buffs are spawned randomly at set locations in the map. Upon hit with the buff, the icon mesh would despawn and the ground circle would attach to the player to indicate the retrieval of a buff. Each buff had a timer that would then activate in the tick to keep track of the duration. After the timer expired, the variables that were changed in the character script are then reset back to normal and the buff despawns.
The targetting system was written to allow you to change the first arrow via the editor in unreal, the code would the create two more identical arrows and space them out accordingly.
When charging the script sets a glow intensity parameter in the material instance for the three arrows starting with the first arrow and then working itself upwards to the last arrow.
The tick always keeps track of how much the arrows are charged, the fire function in the character then multiplies the force of the bombs with this percentage.
A big takeaway from this script was the difference between how variables are set when an actor is spawned in C++ compared to blueprints. In blueprints you can simply expose a variable on spawn and have it show up in the Spawn an Actor From Class node. In C++ you have to use the SpawnActorDeferred method, set the variables and the call the FinishSpawning method to spawn the actor in the game.
Post-mortem & Takeaways
I'm happy with the result of the 10 days that I spent on it considering I also learned C++ from scratch, while I still believe that I have a lot to learn, I feel really comfortable delving deeper into the language. I also feel like it's a language I like working with as I personally like the structure that comes with having separate header files compared declaring everything in one place. The language is very complex, but at the end I felt like there were no major difficulties. By using Visual Assist, I was able to find the functions that I needed or browsing the Unreal Docs for more information. Overall I didn't feel like there were any major challenges in the coding cycle at the end of the project.
This project was a great challenge and really fun to make, C++ is definitely a language I will explore more as I find it extremely flexible and a good way for me to learn the inner workings of Unreal. I will most likely continue working on the project and I will re-write some of my scripts as I have already found ways of improving them both for performance and ease of use in the editor.
I really enjoyed working and learning something new each day. It was great to feel how everyday I was progressing not just in the project but also as a developer and a programmer.