My OBS isn’t working so I unfortunately can’t record the behaviour, but it should be quite simple to reproduce. It’s just this code in _process() and “pistol” is a Sprite2D as a child of a CharacterBody2D.
if aim_direction is a zero vector, all sorts of fun stuff could happen
mixing in previous_gun_tilt means if something goes weird with aim_direction it may take a while to shake out
you might want to pull out that 5 and call it const AIM_SPEED: float = 5.0 or the like
your rotation is mixing previous and desired positions, but your position is set immediately with no mixing, which means they’re not really going to be in agreement if the mouse is moving
This setup does the job, but I figured out the issue in it: when going from a value of about 360 back to 0, it does a full spin the other way. Is this a job for fposmod?