0 votes

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?

in Engine by (15 points)

1 Answer

+1 vote
Best answer

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).

by (29,088 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.