How to rotate a 2D sprite but no the axis, in the editor?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By diego8arock

Hello there,

I had one problem with the rotation of a 2D sprite: a turret, composed of a base and a gun, the things is that the gun was drawn vertically, that is in the y-axis, then I made a script (a simple one, nothing fancy) so that the gun would follow the mouse pointer.

But what I saw was that the gun always pointed 90 degrees away form the pointer, then I realized that the sprite of course was no aligned with the x-axis, so I tried and tried to rotate the sprite in the editor so the gun would by horizontal but keeping the axis as before, but I could not succeed, I have done this in Unity but not in Godot. The only way was to edit the sprite outside Godot, set it horizontally and then import it back (of course I can add PI/2 to rotation but that is too clumsy).

Is there a way to do that in the editor, I know this was a minor thing, but what if, in the future I wan a different angle or something?

:bust_in_silhouette: Reply From: Zylann

Several solutions:

  1. Change your texture so that it points horizontally. But you didn’t seem to like it so…

  2. Add PI/2 to your code. But you also didn’t like it, so…

  3. Add an extra node and put your sprite as child of it, so you can rotate the parent without affecting the extra rotation. It’s a tiny bit more expensive of course since an extra level of transform needs to be computed (even though it never changes).