I'm trying to make it so that a line aims at the mouse position while still rotating around a pivot that is not part of the line. To do so, I've made my own lookatmouse() function that calculates the angle between the x axis and the mouse, and then the angle between the line aiming at the mouse through the pivot and the line aiming at the mouse through the line. The sum of the two gives me the exact angle that makes it so that the line aims at my mouse. However, when moving the mouse somewhat close to the line's center, the angle starts going crazy and rotates back and forth for some reason.
I've got a MRE right here if you'd like to test it out: MRE