I've been messing around a bit with snipers because I've noticed that their movement can be a bit... odd. Odd in the sense that it seems like its random whether they will stand in place in shoot, run to a random direction while shooting, or jitter back and forth while shooting.
I did a close inspection of what targetDest in MovementPlanning.cs was set to when snipers are deciding how to move:
- targetDest is set to your previous command's destination
- It does not get overwritten by the targetEnemyEntity position because setMoveToEnemy gets set to false for snipers
- Then, no matter the distance between entity (the sniper) and the previous destination, the angle is calculated and the next destination is set as ~15000 units away from last frame's destination, along the angle previously calculated
- Since the destination is 15000 units along the line projected from last frame's destination, if you were closer than 15000 units last frame then you are told to turn around 180° and move (15000 - last frame's distance from dest)
- Once in the loop of turning around forever, the sniper will stay that way until it receives a direct move order (not an attack order)
If you target a unit that is immune from outside a certain range (tesla coil turret), then the distance the code tells the ship to move is smaller, but still ends up in the same chaotic loop.
If you were to change the code so that (setMoveToEnemy = true) for snipers, then the snipers act like a normal ship with their kite range being ~15000. This is large, but the snipers can still be hit by the longest of ranged weapons this way (I think most guard posts and eyes have ranges larger than 15000).
An interesting way to change the code would be to equate (setMoveToEnemy = false) as "move to the edge of gravwell directly opposite of your target", but this also sounds like it could lead your snipers to backing away from an enemy right through all of their defences.
What should be the proper reaction of snipers? Don't move at all, run to edge of gravwell based on angle from the center, run to edge of gravwell based on angle from enemy target, stay just outside of your target's range, stay at a fixed range from target, something else?