Pt 31: Friggin' Guns with Lasers on 'em!

1 0 0
                                    

02/04/2024 - Okay, so here is a fun story. With every weapon in the game getting an upgrade, some of the upgrades are fairly basic.

For example, the mod system gives the pistol a burst shot and the SMG gets a 2nd bullet for every 1 it shoots. Both are relatively easy to program and can copy and paste a lot of their code between them...

Then comes the crossbow and the rifle. These guns fill a similar niche in that they are supposed to be slower guns with bigger highs between the slow reloads. I'm not really here to talk about the crossbow's upgrade, nah... 

Screw lasers man...

The rifle, when upgraded... Turns into a laser gun - plain and simple. Originally I had created a laser that it would instantiate where the bullets spawn. Cool, but the laser shot straight down.

Attempted to rotate it, and now the laser shot forward... if I was facing south only, otherwise... it just shot south.

Attempted to fix that and now the lasers all spawn at the center of the map, but rotate properly.

Fixed that and the lasers rotate... kinda. Turns out I had got them to aim towards where the player is looking. Problem solved? Nope!

The weapons SHOULD shoot bullets towards where the cursor is on screen, not the center of the player's viewpoint, as the cursor isn't always there.

Also the lasers spawned on the gun barrel like they should, but I wanted them to hover where they were after firing, independently of the gun. Bob (chatGPT if you don't remember) helped me fix that, but now they were rotating relative to the global instead of anything related to what I was doing.

No matter how much I attempted to calculate and input the gun's rotation into the laser, it would not work...

I kid you not, I attempted to fix this for 2 days, probably 10 hours total before commenting everything out and just putting it back to a bullet to at least let the rifle work when upgraded. Saved my progress and shut down PC to get ready to get mah baby and clean a bit for friends to come over for some Cards pizza and card games.

As the computer shut down, I had an epiphany. While the setting the lasers be a projectile you launch and forget about.... Why not just attach the laser to the gun itself and make it invisible til you shoot, then enable it as though it just got shot, and disable it after. It would 100% follow the gun and basically make it like shooting a continuous laser beam. It would be great for sweeping the enemies as well.

That took all of 30 minutes to implement. The code and making sure it worked and that the laser got loaded into a variable to enable and disable appropriately... That took about 2 hours.

Needless to say, I now have all 5 weapons with appropriate upgrades!

Now I just need to do a bit more testing and the actual game section is done. All that would remain is tutorial, main menu, alt modes and trailer and I'll be done :)

Zombies and the One Hand Army - Dev LogsWhere stories live. Discover now