
Procedural Sword Generator
Procedural generated content has been used in games for level generation and weapons such as guns. What if it was used to create a large variety of both realistic and unrealistic swords?
Honours Project
For my fourth year in BSc Hons Computer Games Technology, I decided to design and implement a prototype that can procedurally generate swords.
Aim
To design and implement a program which will procedurally generate swords with defined edge/edges, mass and unique form, based on historical and fictional examples.
Purpose
Procedural (Content) Generation (PG or PCG) is a technique used to create content using algorithms and rules. Once PG is implemented, this can reduce the workload on a designer as a potentially limitless variety of assets, such as weapons, can be created in a moment. Another advantage of PG is the ability to easily make changes to the assets generated. Need all swords to be a fraction longer or only create swords from a certain period? One small change to the rules for PG and all swords generated will now be longer and only from the specified period.
Process
Language: C#
Game engine: Unity
​​
​The prototype was designed and implemented in Unity as a package. This allows the PCG to be added to future projects.
​
To store data collected from various swords, several CSV files were used and read into Unity. CSV files were chosen over JSON for their small file sizes and ease of deserialising into Unity.
​
A random selection of parts is selected and combined to create a sword. Using the data for each part in the CSV files, meshes are generated for a visual representation of the sword. This is done by calculating the positions of each vertex based on the length, widths and thickness of the sword at different points.​​

The volume at different points of the mesh is calculated. This is then added together for total volume, and is also used to determine the point of balance of each part (which will be used later). With the total volume of a sword, the weight or density of material used can be calculated. This allows any changes in the dimensions of the sword to also effect the weight.
​
For the shape and design of the sword to reflect in gameplay, a series of calculations can be performed, based on real world physics, to estimate the damage to a target by the sword. Factors such as the the swords weight, speed, impact point along the blade and the weight of the target, can change the damage the sword causes; This can influence a players choice in weapon or strategy and can create more dynamic gameplay than standard statistics and hit zones.

Conclusion
The prototype successfully generates swords and their meshes. With the small number of parts currently added, various unique designs are possible and can be improved by adding more parts. The width of each part can also be randomly increased or decreased.
​
There are however a few errors and issues with ease of use and flexibility in parts of the mesh generation, such as the position of vertices for curves are incorrectly calculated, and it can be difficult to enter the correct data for parts. Several next steps to further improve and correct errors in the prototype are required.​
Continued work
As an ongoing continuation of this project, to solve issues discovered during prototyping, a second prototype is being designed. This will improve or replace functionality and ease of use of the original design in areas such as:
​
-
CSV files used for storing data are changed to more readable JSON files - to keep it's memory footprint down, a program to convert JSON to CSV can be created
-
Structs for storing sword data in Unity are simplified and also add greater flexibility in the positioning of sword parts
-
Implementing an algorithm to generate meshes to replace the simpler brute force method currently used
-
Correcting errors in the calculation of a swords total kinetic energy before and after an impact
-
Designing a program to create swords visually and view generated swords outside of the Unity Editor
Code
​Honours Project - Source code (GitHub)
Continued Work - Source code (GitHub)