Help with gun orbit

Your problem is distance_to_point.

You are setting the position of the gun relative to the mouse and itself, but what you want is to set the position relative to mouse and player.

Since you are setting the position relative to the mouse and gun, when the mouse is in between the player and gun, then lengthdir is towards the player so the gun will appear on the other side of the player, and then on the next step the gun will move back since the mouse is on the opposite side. So it will cause a flickering effect.

What you want is to set the position relative to mouse and player. Which means you should call your current code inside the player step event. There are other ways to fix it but this is the easiest way to reuse the code you posted.

/r/gamemaker Thread