Wednesday, March 6, 2013
Summary
Now that's what I'm talking about!!! Today is the kind of massiveness that needs to be happening everyday
Today, I finally faced my fears, and attacked the thing that I've been most worried about for the prototype: combat AI. I spent the whole day working on it, and I've come a
long, long way since this morning. There's still loads more to do - I mean, combat AI is a pretty essential part of a space sim. But I'm feeling a lot better about it already!
I started off by doing some serious thinking about what combat AI should look like, and came to the conclusion that I've been approaching it incorrectly. Previously, I've been thinking of combat from the "what would look cool" viewpoint. That's really a terrible idea. I don't design features around "coolness," why should I do that with combat? Besides, it's entirely too subjective. So I've switched my approach to the same approach I use for everything else: make it good for its purpose. The point of combat is to destroy/disable the target. So optimize the AI for doing that. You're probably about to turn off the computer and dismiss me as a total idiot, since it's such an obvious statement. Bear with me though! I promise I have a few interesting things to say about this.
The first thought that comes immediately when you start thinking about optimizing combat is "let's not get hit by the enemy." How to do that? A few options: first, you always want to maximize lateral movement. Heading straight at the enemy is an awesome way to take plenty of bullets to the face. Second, you want to be smart about the distance that you keep between yourself and the enemy. If the enemy has point defenses that will rip you to pieces at 500m, but you've got homing missiles that can work well beyond 5KM, why on earth would you ever get close? Conversely, if you're attacking a slow target with massive turrets, you might take advantage of the tracking rate of large turrets, and try to get as close as possible to the target so that the turrets can't keep up with your angular movement. So the question of "optimal range" is really a very big part of combat. It gets even more interesting when you consider weapons with magazines. Maybe you'e got a short-range rocket rack with 16 shots that takes 1 minute to reload. The optimal range then become time-varying: you want to get close, launch your rockets, then get back out of range while you wait for your magazine to reload.
Believe it or not, however, the first observation of lateral movement actually does a
lot to help us solve the problem. In fact, if you consider the "optimal range" to be a constant, then it is a mathematical fact that the ideal behavior would be to fly on the surface of an imaginary sphere surrounding your target, where the radius would be the optimal range. This is a fact from differential geometry, that the sphere is precisely the surface whose tangent plane is always aligned with the "view" vector from the origin. It means that if you're flying on a sphere around a target, then you've maximized your lateral velocity with respect to the target. Intuitively, you know this to be true. Just think of the simple case of flying circles around your target (circles lie on a sphere) - this is obviously a good strategy for not getting hit! So really, combat AI reduces to the problem of determining an "ideal range." Once we find that ideal range, then we simply fly on the surface of a sphere of equivalent radius. We will, of course, add some randomness to make our path less predictable, and also to break the appearance of a mathematically-perfect flight path. We can very easily handle the notion of dynamic ideal ranges: all we do is increase/decrease the radius of the imaginary sphere on which we're flying!
Of course, there's more to it than that. After considering those basic things, we also want to start taking into consideration more complex ideas, like the fact that certain angles of approach are visible to less of the enemy's turrets than others (if they have lots of topside turrets, we obviously want to stay below them), etc. To get really fancy, we can even start to take into account the surroundings, perhaps using asteroids as bunkers while we wait to reload.
Today I have just done the basics described above, nothing very fancy yet. Already, however, the AI is quite effective. It's very challenging dogfighting them, especially in numbers. I must say, it's already pretty fun to play! I spent quite a while today dogfighting with the AI (I hope you'll excuse the testing time, since, after all, I was trying to build a good combat AI today...)
I did a lot of other stuff as well, but it all funneled into combat. One of the bigger changes was making turrets track linearly, rather than using my prized exponential falloff. Exponential is so great for so many things...but not for turrets. You want your turrets to track at a constant angular velocity. As I found out today, doing so makes aiming
wayyyy easier. I'm not sure why I ever thought that falloff was a good idea in the first place. Along with this, I added an attribute to weapons: tracking speed. I'm sure you already expected this to be in the game, but now it's officially there. You'll need to pay careful attention to this attribute when you're purchasing weapons,
especially if you're a big ship. A big ship must rely almost completely on its turrets' tracking ability to hit enemies. Whereas in a fighter, you can maneuver the ship itself along with the turrets to obtain a fast lock on the target, with a cap ship it takes too long to change the direction of the entire ship. So if you want to be well-defended against fighters, you're going to need to make sure that you have some weapons with fast tracking and fast munitions.
Speaking of capital ships and their ability to defend against fighters...that's what I'm working on right now! I'm implementing per-turret target prioritization and tracking, using some of the mathematical secret sauce that I previously referred to as "p_hit". Already, even with fairly simple calculations, cap ships have become quite good at prioritizing targets. You can see, for example, that they will immediately punish any fighters that make the mistake of flying directly at the ship - such fighters become high-priority, because they are very easy to hit. It's really nice to see all the turrets picking their own targets...really makes for an epic combat scene, as fighters are exploding all over the place. I've currently got 50 fighters attacking a battleship, and am using this as my test scenario to perfect turret prioritization and tracking. So much fun!!!
Phew, big log today...sorry, it was such an exciting day, and combat is one of those things that's super fun to talk about
Hour Tally
Coding: 8.17
Internet: 1.97
Testing: 3.52
Thinking: 0.80
Total Logged Time: 14.46
Comments