bg

Weapon Attachments - Fire mode, Flashlights, and Laser Sights!

Dev Log #24

Ever since the early stages of development, I've been eager to incorporate weapon attachments into the game. I've been coding things up so when it came time to add them it would be simple. Turns out it was. I dropped a 'Modules' component onto weapons and added a new 'ModuleType.WeaponMod' and bam. Dedicated weapon slots were available. I next took the flashlight and made a new weapon attachment version.

Flashlight weapon attachment

Having a flashlight on your gun is a huge improvement over having to create and hang onto a dedicated item just for a light. However, what I was really excited about was adding laser sights. Armed with my recent foray into shaders, I was determined to create visually striking laser beams that captured the mesmerizing essence of lasers cutting through fog.

Unity shader graph for laser beam effect

Creating the laser effect involved a shader that can be broken down into three main components. The blue box handles the beam’s shape; the green box overlays a smokey texture using Voronoi noise and world coordinates, creating an illusion of the beam intersecting with airborne particles. This layer shifts subtly, mimicking the natural movement of smoke. The red box introduces fine speckled noise to simulate the sparkling of light particles within the beam. This is all combined and added as the material to a line renderer.

Check out the effect in action!

I loved playing with this shader and giving the beam different colors which led me to provide players with the ability to customize the color of their laser sights. Drawing inspiration from the intuitive UI of Helldivers 2, I integrated a color selection feature via a new modular Equipment Menu, which avoids adding clutter to the inventory screen.

Equipment menu for held item

This method allows players to modify weapons on-the-fly by holding the reload button, seamlessly integrating with existing inventory systems. I also introduced a simple toggle for turning mods on and off. I also threw in a 'fire mode' toggle for guns.

Check out the color selection in action!

I’m thrilled with how this new menu system turned out; it’s straightforward, versatile, and a perfect fit for Starlab!

Next Star Over logo

© All Rights Reserved Next Star Over 2024