Hello. I am making a top down shooter game. The character should rotate towards the mouse global position. Something like this:
As you can see, the character changes their sprite and the gun changes its rotation according to where the mouse is pointing at. Also, if the mouse is pointing down, the gun shows in front of the player. As you can see in the GIF below:
Character with gun in front
As I have seen. The character uses 4 different sprites (one looking at the front, at the front right, the right, back right and back), and then it flips the sprite according to the mouse.
The gun could be a separate sprite that does rotate looking to the mouse.
I have tried all of this, however, it looks pretty weird, and the direction detection tends to fail sometimes and the code is too messy. What would you recommend me to achieve this in the best way? Thanks.
PS: The game in the gifs above is "Enter the Gungeon"