During the development of Scrapload, we originally planned to have grenades as a secondary shot fired from the players gun. As I was responsible for programming the character controller, I was tasked with creating the functionality that launched the grenade. Unreal Engine already has a built-in function that will solve all of this for us, but it lacks any kind of customisation that I wanted. My goal was to provide a tool that gave us the ability to tweak certain details of the grenades trajectory, such as:
Launch angle
Launch velocity
Maximum distance travelled
Maximum arc height
These customisations were helped us to find the right game feel that we were aiming for, allowing us to iterate based on playtesting and feedback early on in development. To meet this goal, I developed three grenade launching variants, each with different adjustable parameters. The three variants were:
Launch angle determined by players look direction
Adjustable launch angle and maximum distance travelled
Adjustable maximum arc height and final distance travelled
These three variants allowed us to experiment with different mechanics so we could quickly fine-tune the grenade and determine which best suited the game’s design and player experience.
The grenade will follow a parabolic path which is determined by its initial velocity. For simplicity, drag (or air resistance) is excluded for this project, so it is moving at a constant speed with gravity being the only force acting on it. Because of this, I was able utilised a number of kinematic equations when approaching this task. These equations use different variables to calculate another, where you only need to know three of them to solve for the unknown. I used a total of five variables to do this:
Initial velocity - the speed and direction at which the grenade is launched
Start position - where the grenade is launched from
Final position - the position at the end of the launch (target position)
Gravity - the force pulling the grenade down
Height - the vertical displacement (maximum arc)
By substitute these variables into the kinematic equations, we can now adjust the trajectory which the grenade travels along.
Since Scrapload is a first person game, it felt like a good option to test out using the players looking direction to determine the angle which the grenade would launch at. When putting this together I noticed that the higher the look angle, the shorter the distance that the grenade would travel. When play testing this, it was noted that players expected the grenade to travel further when they looked up but were disappointed when that wasn't how the grenade acted. To fix this, I introduced an 'acceleration' variable that would affect the initial launch velocity. But I quickly discovered that the higher the launch angle, the further and stronger the initial velocity would be, sending grenades much further than anticipated. This lead me to introduced a 'max velocity' variable that we could tweak to limit the overall intensity of the launch and finding a balance between higher and lower launch angles.
The next approach focused on allowing us to specify both the launch angle and the maximum distance the grenade could travel. It designed to give us full control of how each projectile would be launched, as the parameters for every launch would be identical. By adjusting the two parameters, we could control the grenade's launch velocity, where the lower the angle and further the maximum distance, the faster the grenade would travel.
5° angle, 100 meter maximum distance
50° angle, 100 meter maximum distance
Lastly, I felt we were missing the flexibility to specify the arc height for the projectile, as well as the distance to travelled. Having these two variables set by us was enough to determine the launch angle and velocity. Originally, I had the maximum arc height to be defined by meters, where I then inserted this value into the an equations to calculate the launch angle. However the end result wasn't what I had expected, where the lower the number was, the higher the arc would be. This seemed counter-intuitive to use, so I changed the maximum arc value to a decimal range as a way to adjust the intensity of the arc instead, with 0.1 being minimal and 0.9 being maximal. Not only did this change allow for better ease-of-us, it also ensured that the arc height and distance were closely related enough to ensure that grenade is still physically possible. Now that I had the angle calculated, I then used it to determine the grenades initial velocity when it is launched.
Different maximum arc height, same distance
Same maximum arc height, different distances
As the game changed throughout prototyping and development, grenades were eventually removed from that game as we moved towards a more passive-like player style. Overall, this was a great learning experience where I was proud to be able to address a problem we had and learn something new along the way. I was able to provide multiple different solutions to one issue, so we were able to tweak the player controller to suit what our game needed and enhance the overall feel of the grenade launch.