Finalizing the weapons

Continuing off of last week’s post, I’m going to talk about the various changes and additions I’ve made to the weapon system and how I’ve just about finalized it.

ANIMATION

This week my artists sketched up the final weapon that was implemented into the game and also added animations for all the guns. Adding them to the weapons themselves was fairly easy. I coded in the base weapon that whenever the player fires a shot, it would trigger an animation event on the weapon. I exposed the trigger name as a public variable, allowing me to simply adjust the animation name from the Unity Editor instead of having to manually implement it for each weapon.

This is not so much animation, but I’d say it tacks on. I decided to add recoil to the weapons whenever they fire. Currently it works on the principle of making a randomized vector every time the gun fires and sets a recoil-smoothness float which I use a Lerp to adjust the position of the gun between it’s original position and the original position + random recoil offset. The Lerp float reduces in to 0 over-time at an adjustable speed. With that in mind, in order to finer tune the recoil, I exposed the Minimum recoil, Maximum recoil and Recoil recovery speed as exposed variables.

WebM Example

AUDIO

One of the most glaring issues I immediately noticed was that the firing sound got cut off every single time you started playing it. This is because 1 entity cannot seem to emit more than 1 sound at the same time. So as an alternative, what I did was create a temporary audio entity at the current location of the entity spawning it and modify it as I pleased, which solved the issue of sound stacking.

FINALIZING

One of the final issues I noticed was that the bullets didn’t always come out of the end of the gun. This was due to the fact that each gun has it’s own size and I can’t always make sure that the bullets come out the same part of the sprite, since this isn’t a 3D model with attachment points. So, as an alternative, I made a code-relative attachment point for the guns and exposed them as public variables, so the creation point of the bullets can be adjusted through the Unity Editor for each weapon.

WebM Example

One thought on “Finalizing the weapons

  1. Nick this is an excellent post!

    Something that i really liked with the post is how you explain things, rather than just go too deep by explaining the core function on how to do the things you set out to create. You explain your mindset on how you thought on the matter in a clean and brief way letting me as a programmer look at it, understand it, and then be able to implement it if that is what I desire.

    Something that I do wonder about is why decided you use a random recoil offset variable instead of a set one? You probably use it to gain a diversity in the recoil an make it feel more realistic/alive. In that sense the implementations is really clean and well thought out with the smoothing float with the lerp. Gold star to you!

    Overall I really liked it and will probably look in to adding my own smoothing float variable to my weapons so that I can maximize the feedback on recoil.

    Like

Leave a comment