Melee Gun Thrashing
Using Swarm Targeting with gaussian kernel density usually gives a single angle which doesn´t change often.
Gun thrashing means the bot keeps changing its mind every tick. Usually happens when you target the closest bot and there are 2 or more bots with similar distances.
Swarm targeting (which is what I am using) can change rapidly too, because of the discontinuities caused by scanning new robots. For instance, if you are aiming towards a bot, then scan them and discover they moved further away and in a movement pattern you haven't seen before, suddenly it is better to target a bot on the other side completely. Of course, I'm using a square kernel instead of gaussian, I might try a 1/(x^2 + 1) kernel sometime but I've never found improvement over square when targeting.
Uniform kernel gives a bunch of tied best angles. If you use random tie-breaking and recalculate every tick, then the gun can thrash a lot. Generating a random number only once per shot solves the problem. I used it before switching to gaussians.
But it doesn´t solve the problem of turning the gun 180 degress. Besides Swarm Targeting, the only thing my bot does to avoid it is trying to stay near walls/corners.
Most articles dealing with gun thrashing in melee try to lock the gun on a single target.
Hmmm, I weight each hit based on the inverse distance that the KNN point had to the current point, so I don't have that problem. I'm just thinking, that isn't made equal on a per-enemy basis, so if one enemy has KNN points closer together its points will be weighted higher. Hrmmm... at the same time surely those shots are of a higher certainty? Will need to test.
Maybe inverse distance is overflowing kernel density estimation. When KNN distance is too low, classification score tends to infinity. The result is a bunch of tied angles with infinity classification score. Depending on the tie-breaking being used, the gun can trash a lot too.