Okay, so it’s been a year. In my defence, I’ve been working on real, grown-up stuff that people actually pay me for during that time, so I’ve not really had the opportunity to work on what is essentially a personal project.
However, I have found myself with a bit of time recently, and have been contemplating some of the issues I had previously had with Dreadnaughts.
I also had a good think about how it all works. Dreadnaughts is a very simple concept, but it relies on some horribly complex methods to make it all work. So simplification is the next order of business.
Bearing in mind that while I have some free time to work on it, I don’t have a lot of free time, I’ll be working on rewriting small bits as and when I can.
To this end, I have tackled the turrets. Previously, they didn’t really work properly. All they have to do is to track the player and shoot at them when they’re in range, but within a limited range of movement (turrets should not be firing through their own ship!) and it was all a bit of a shambles, really. I did get it to a working state, but I have no idea how, and that’s not a good thing at all.
So I rewrote the code for tracking and constraining, and it works perfectly. In three lines of code. So that was splendid.
The rest of the turret code was shambolic, however. I had one master script for each turret, one for the rotating base, one for the rotating barrel and one for the muzzle. The master script had to find all these scripts at runtime, and then spend all its time sending them information (this is your target. You can fire now, you can’t fire now etc) Inefficient doesn’t begin to cover it. So I rewrote the whole caboodle to put it all in the master script, where it’s all very happy and about 5 million times more efficient than previously (estimated)
Next up is to change the way the turrets fire – they currently launch projectiles which is particularly messy in the case of the concussion turret which is a rapid-fire minigun. Each projectile is a physically-simulated object that has to be kept track of, and that can be a lot. So instead, I shall employ a raycasting approach, where the turret draws an invisible line to work out if it’s hitting the player or not, while launching particles that look like bullets as a purely visual effect.