Cycerin: The issue there is that you're clamping X and Y independently of each other. What you actually want to do is clamp speed, not velocity.x & velocity.y.
So, some psuedocode:
float speed = Math.sqrt( velocity.x * velocity.x + velocity.y * velocity.y );
float targetspeed = some calculation involving current speed, max speed, & deceleration - basically, what speed do you actually want to be going at right now.
float multiplier = targetspeed / speed;
velocity.x = velocity.x * multiplier;
velocity.y = velocity.y * multiplier;
You may also want to do some extra work with your fluxIsAtZero value & hard-coded zero-flux speed boost of 50 to account for possible skill perks (which can allow "zero flux" to persist up to 25% flux, and/or, cause the zero flux speed boost to be 75 instead of 50.)
I'll reply since I wrote a lot of that code:
We tried some of that. The problem is that there is no direct code method to clamp speed itself (you can set maxSpeed but the game does not force the ship down to that if it is over that max speed and coasting, only if the player is actively holding a direction key), so you have to deal with the Vector2f velocity in some way.
So the issue isn't that it's not working--it is working--but rather that under some conditions (triggered with diagonal movement) there is a small "bump" in a cardinal direction near the end of the system working.
Part of the problem is that from what I can tell, Starsector uses the deceleration value of a ship to determine how fast it can change its velocity vector between the X and Y directions. (as a bit of explanation, in Starsector the velocity vector X is side-to-side movement relative to the ship's heading, and Y is forward-backward movement relative to the ship's heading). So, we drop the deceleration value to prevent players from slowing down rapidly in the Y direction (you can't move forward and then stop on a dime).
Good point about the skill perks though. If we can get this last "bump" figured out, I'll also update the code. Anyone know of an easy way to do this, or does it just involve calling some character skill functions?