Careful with that firing rate, Eugene!

Lately I have been working on the Combat Badger vehicle’s weapons. It sports a twin-barrel automatic cannon in the front and a grenade launcher in the back. The vehicle itself was introduced in the previous blog post but the weapons were missing materials as well as the actual firing logic.

The first thing I did this week was finish the modeling and texturing of the weapons. You can see the result in image 1 below:

The weapons of the Combat Badger vehicle, a twin-barrel automatic cannon in the front and a grenade launcher in the back.
Image 1. The weapons of the Combat Badger vehicle, a twin-barrel automatic cannon in the front and a grenade launcher in the back.

Next up was to implement the actual logic for the weapons. The twin-barrel cannon was first on my list. It was fairly straightforward to implement as it resembles the gatling gun found of the roof of a previous vehicle, which meant I was able to use a lot of code written for that weapon. Most of the work was making it so that the cannon alternates between its two barrels, and spits out a shell after each shot.

The grenade launcher was another story. It is different than the cannon in many ways. First of all, it is not a hitscan weapon; it launches an actual game object (the grenade) which has its own physics body, mesh, particle systems etc. It is also not an automatic weapon, which will become important later. The grenade launcher fires its projectiles in an arc, rather than in a straight line like the hitscan weapons. This makes aiming with the grenade launcher a fair bit tricker than with the cannon, and since the Combat Badger will be an AI vehicle in the demo (which should be ready this spring), I used the AI drivers a lot during the development of the grenade launcher. Rather than using it for the player vehicle I let the AI drive around and fire grenades, making sure the aiming worked as I expected.

When the launcher worked well enough I tried it out myself. Imagine my surprise when I found out that I had accidentally created a fully automatic grenade launcher! When trying to launch a single grenade I accidentally launched fifty (see image 2).

The fully automatic grenade launcher in action. The grenades' smoke trails make it hard to see what is going on.
Image 2. The fully automatic grenade launcher in action. The grenades' smoke trails make it hard to see what is going on.

Why was this not the case with the AI vehicles? When I started working on the grenade launcher I copy-pasted the code for the cannon and started modifying it. As it turns out, I forgot to change the firing rate from automatic to single-shot. The AI with its computer-brain accuracy can keep the trigger pushed just long enough to launch a single grenade. Me on the other hand, not so much. The fix was very simple; make sure the weapon only launches a single projectile every time the trigger is pressed. Check out the video below to see what happens when you launch tens of grenades into a pile of dynamic objects.

Video showing the Combat Badger's weapons being tested, as well as the accidental fully automatic grenade launcher.

It almost looks like fireworks! An automatic grenade launcher is probably not going to be featured in the game, but new interesting gameplay mechanics often emerge from mistakes like this.

And of course, all weapons in the game are data driven, so if you really want this in the game, you can just change the firing rate back to fully automatic in the data files ;)

Prev: Status Update - January 2021 Next: DevShot #1