Sprite ox/oy and angles

I'm having an issue when messing with sprites angle.

By default, the maker first calculate the ox/oy coordinate and then spin the sprite to the angle set, so this happen:

Let's say i have an icon, centered with ox = 12, oy = 12 (half of the icon size, so it's centered) and angle = 0°

icon1.PNG


If i change the angle it will spin on it's onw center so it's x/y position don't change.

if i change it's oy + 10 it will move up:

icon2.PNG


Then, when i change the angle, the issue appears, let's say i changed -90°. the icon will spin and it's x/y will change

icon3.PNG


icon2-3.PNG


In the end i set to change the icon Y (vertical) but he moved horizontaly.

So what i want is a way to change angle and ox/oy, without changing the final x/y. so if i set +10y and 90%, the icon will be angled to 90% 10 pixels above the center.

This question is more about math than scripting itself.
Just had a quick go does this work for you?

Edit: Right I think this should work for every case, let me if that isn't the case and I can try again.



Code:
  def move_rotated_sprite(sprite, axis, amount)
    a = (360 - sprite.angle) * Math::PI / 180
    case axis
    when :x
      if (sprite.angle >= 90 and sprite.angle < 180) or 
      (sprite.angle >= 270 and sprite.angle < 360)
        amount = -amount
      end
      sprite.ox -= Math.cos(a) * amount
      sprite.oy += Math.sin(a) * amount
    when :y
      sprite.ox -= Math.sin(a) * amount
      sprite.oy -= Math.cos(a) * amount
    end
  end
Fomar thanks, things are working now as i wanted 😀

I totally sux in geometry and anything related to angles, i knew that i should use sin and cos somehow, but i had no idea how,



Code:
a = (360 - sprite.angle) * Math::PI / 180
this was the solution i was missing =]
No problem glad I could help. It took my a while to realise that it rotated anti-clockwise, just like you it seems.
Oh, the math modules expect everything in radians.

That explains a lot lol

Original thread: https://forums.rpgmakerweb.com/threads/sprite-ox-oy-and-angles.3075/