User Tools

Site Tools


160310 - Thoughts on Weapon Scripting

After tinkering with the scripts the last few nights, I'm pretty much at “banging my head on my desk” status when it comes to proper weapon scripting. At first I made a really simple raycast weapon that transmits damage done to any object it hits (which actually only does something if the object in question has a objHealth script).

This was all well and dandy for a quick test, but for more complex weapons I need more stuff:

  • Logic
    • Something like a basic state machine where the weapon is either FIRING, in COOLDOWN, or READY
  • Damage it does
  • Cooldown time and rate
  • Heat generation
  • Max Ammo
    • Could also be infinite

Additionally, some weapons utilize raycasts while other create projectiles, and those require different things. Raycasts need to know:

  • Number of rays
    • While a chaingun or railgun will only fire one ray, something like a shotgun or flak cannon would need several
  • Accuracy
    • Definitely want some sort of cone the ray could fall within, adding a small amount of randomness to the shots

And projectiles need to know:

  • Projectile prefab
    • Rocket, grenade, laserblast, whatever it is this thing's supposed to launch
  • Sequential, sequential rate
    • Maybe a missle launcher fires off a series of rockets on each shot? LRM in MW2 does this

It's 8:19pm now. After a lot of thought, I've decided the best way is to cram all this stuff into one base class, and create a very nice, responsive Inspector UI for it (which I'll make later). This'll keep everything consistent, and it really shouldn't get THAT complicated. It's a basic state machine with a few public variables (some of which are straight-up ignored depending on the weapon type) and one or two public functions. So long as I keep it well commented it shouldn't be too hard to decipher what's going on either.

blog/160310_thoughts-on-weapons-scripting.txt · Last modified: 2016/03/10 17:24 by admin