Pt 5: Reloading and Accuracy

1 0 0
                                    


08/28/2023 - So after the fun debacle with infinite loops, I had to next implement an ammo system. As I mentioned previously with Gun Swapping, you need to also swap the ammo amounts when you do trade weapons, well that info isn't as important until it comes to reloading.

When I started making an edit to the script for reloading, I thought it would be simple but then a lot more variables came into play.

So you have Gun 1 - can hold 10 shots in its clip, say you can hold 100 bullets total.
Shoot all the bullets, you reload and now you have 10 bullets in clip and subtract those 10 from the 100 to get 90 bullets left held.

Cool, now say you are like me and constantly reload at any sign of minimal downtime. You end up with odd numbers such as 77 bullets held. Weird but nothing of concern.

Say you keep using that weapon and get to 0 bullets in the chamber but only have 7 held - if you reload, you can't get a full clip, but only 7 bullets.

Likewise, if you only need 3 bullets for a full clip and you reload, you only need to subtract 3 from your remaining ammo.

I actually forgot this step and was just setting all reloads to max ammo >.>

Well, if you can't tell, I basically got it work.

~~~~~

As for accurate shooting, basically the game was giving weird bullet trajectories when I shot, so I wanted to revamp projectiles. Instead of just launching away from player, what I did was set a 2nd game object further down the barrel and compared the point the bullet launches from to the 2nd/new game object and used the 'transform' difference between them to generate an angle for the bullet to go.

This worked well once I got past the Bullet projectile script not recognizing the equipped gun. To resolve that, I had to essentially reference the player in the bullet script... Then find the gunAnchor game object, and lastly recursively find both BulletLaunchPoint game objects for the reference.

This took the better part of an hour and a half to get to work after a few failed attempts.

Now it shoots with fair accuracy~!

Next will probably be a zombie spawner/wave system and bullet deviation.

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