[solved] how to change the basic rotation of a sprite?

OK. We are talking about a Top-Down game, where I want to control a vehicle with an angle and a force.
So the basic angles of GDevelop are 0 = right, 90 = down, 180 = left and 270 = up.

My Problem is, that all my graphics are like they move from bottom to the top.
When I set a angular force to the object it always looks like its moving sideways.
Is there a possibility to change the initial rotation of the sprite or do I have to do that in my graphic editor?

--------------------------------------------------Anwser-----------------------------------------------------------
The default rotation of an top-down sprite should be showing to the right / east / 0°
You can change the basic rotation of an sprite in a graphic Editor or by code.
Read the post by ddabrahim in this thread to learn how.

The easiest way that I know is to do it in the graphic editor.
If someone else knows a better way, however, I’d also be interested to hear. :slight_smile:

If not existing already, we could suggest a “reset rotation” action for Gdevelop, which resets the initial rotation to the current rotation, giving you the ability to change the rotation starting point as desired. The same with reseting initial position, which could give you a way to change the position axis of the object (e.g. rotate one object around another without calculating much yourself).

Maybe I’m missing something as I don’t understand the bit about “my graphics are like they move from bottom to the top”, but can’t you just change the rotation of the object to match the angle of the force?

Something like:

Add to Enemy a force, angle: 45 degrees and length: 20 pixels
Do = 45 to angle of Enemy

Obviously you would store the desired angle in a variable and set both to that stored value.

About the “from bottom to top”-Part:

I use a top-down picture of a car and the front of the car is showing to the north.
The example graphics of GDevelop are all showing to the east.

This is the default rotation of sprites in GD so keep that in mind when you prepare your images.
There is no way to change that in GD, but in case you really want to work around instead of rotate the images using an image editor, just simply take in to account it rotation and do some math.

For example in case you want to move your object forward using it angle and the image of the sprite is facing north by default, just do “object.Angle() + 270”
This is because the default Angle in GDevelop is “0” degree but in case your image facing north, that is “270” degree, so your sprite is always going to be off by 90 degree but as we are rotating clockwise it 3x90 to get 270 degree and you need to calculate with that and also with the fact the coordinate system is moving from 0 to 359:

0 degree: east (default angle of sprites in GD)
90 degree : south
180 degree : west
270 degree : north (and goes around up to 359 and then 0 again)

So in case the sum of “Angle + 270” is greater than 359 then you need to subtract 360 to get the proper angle.
For example if you rotate your sprite in the editor downward so it is actually facing south that is 90 degree in the coordinate system but because your sprite is off by 90 degree, it is actually means 2x90 which means 180 degree for your sprite and the sum of Angle (180) + 270 is 450 which is wrong, so if you subtract 360 then you get to proper degree which is 90.

So the formula need to be something like this, I’m pretty sure there is a better way to do this but I’m not very good with numbers.

myAngle = 270 forwardAngle = object.Angle() + myAngle If forwardAngle > 359 then forwardAngle = forwardAngle - 360

Whenever you need to work wit the angle of your object, instead of using “object.Angle()” expression just run this calculation first and then use the “forwardAngle” variable in place.

Or, simply load your images in to an image editor and rotate them to face east and save :wink:

1 Like

As a tip, you can even use windows (select multiple images in the folder, then click rotate > right, or rotate < left, etc.).
No need for an image editor, although I almost always used an image editor so far. :slight_smile:

There’s a great explanation above about calculating your own angle offset, but I would not recommend making the project any more complicated than it needs to be. I add the angles myself too sometimes, and I find it much better if I just rotated the images instead, the code is simpler and cleaner to read.

You can just use mod (modulo) which gives the remainder of the division of a number by another number.

E.g.
1 mod 10 = 1
2 mod 10 = 2

10 mod 10 = 0

11 mod 10 = 1

20 mod 10 = 0

21 mod 10 = 1

E…g if we divide 20 by 10, we get 2, and there is no remainder (nothing remains, 2 is the full result), that is why 20 mod 10 gives 0, as nothing remained.

If we divide 5 by 10 (5 mod 10) 5 actually remains. Why? Well, can you divide 5 rocks to 10 people so that each person gets a rock? No, you can’t, so 5 rocks remain. You would need to take a hammer, split each rock into 2 equal parts, and then give everyone a part… :slight_smile: That’s why 5/10 gets us a decimal 0.5 result. It’s not something we can really divide without cutting it into parts.

So, for angle, use any number mod 360 and it will give you a number from 0 to 359 (360 is the same as 0, so you don’t need 2 of the same angles). :slight_smile:

So, here is the code with modulo (it is simpler, not more complicated than dividing or subtracting yourself!) as you will see:

myAngle = 270 forwardAngle = mod(object.Angle() + myAngle,360)

Thank you. Thats what I wanted to know.
But as kalel sayed, that would be a usefull feature suggestion.