Rotate Picture in a certain angle.

The Rotate Picture command rotates the picture indefinitely, until I give a second command for it to stop. I want a picture to rotate to a certain angle and then stop rotating. Is this possible?
Don't know about pictures, but Sprites have an @angle attribute that can be used for rotation. You would have to use a script to manage it, though, and make sure to dispose it when it's no longer needed to avoid memory leaks.
Pictures have it too. I tried to make some script calls but they didn't work.


EDIT: Ok, I actually solved it.

I created a conditional "screen.pictures[x].angle == y" and then I set the speed to 0.
For some stupid reason, the first time I replaced "y" with a negative value, which of course didn't work.

I'd like to thank lavra for pointing out the interesting fact that sprites can rotate too, something I plan to put to good use.
$test = Sprite.new$test.bitmap = Bitmap.new("Graphics/Battlers/Slime")$test.x = 100$test.y = 100$test.z = 1$test.angle = 270
This displays the Slime battler at position x = 100, y = 100 (in pixels, not tiles), rotated by 270°. z needs to be higher than 0 to be visible at all (Windows have z = 10 by default). On a later point you would have to call:

$test.dispose
to free up your memory.
Pictures have it too. I tried to make some script calls but they didn't work.


EDIT: Ok, I actually solved it.

I created a conditional "screen.pictures[x].angle == y" and then I set the speed to 0.
For some stupid reason, the first time I replaced "y" with a negative value, which of course didn't work.

I'd like to thank lavra for pointing out the interesting fact that sprites can rotate too, something I plan to put to good use.

Would you break this down for me step by step? I tried to replicate the script but it doesn't work.
You want me to explain to you how the conditional for stopping the rotation works?
You want me to explain to you how the conditional for stopping the rotation works?

Yes, please, the condition and the script. I tried to use the scripts you and lavra mentioned in the topic, but to no avail.
Sorry for the late reply.

It quite honestly has to do with how fast your picture is rotating and how often you check for its angle. If the picture rotates too fast, then Ace will not be able to "find" it in angle you want to.

1. A "patchwork" way to do it, is to give your conditional a margin of error. Have this script call inside a conditional:
 


screen.pictures[1].angle >= 200 && screen.pictures[1].angle <= 210


If you put that little script in your conditional, then instead of checking for a single angle, Ace will be checking for an angle that's bigger than 200 but smaller than 210. That way, if you check every second frame, even if Ace misses you initial value (200) it will still stop somewhere relatively close, with the largest possible diversion being 10 degrees (210). The larger that gap is, the easiest it is to stop the picture for higher speeds.

I tested it for a -5 speed, I checked every 2 frames and it worked. (Test project, no scripts).

Spoiler
0EDmjyj.png




But if your picture rotates much faster than that (double digit fast), then that won't be enough.


2. A second way I came up with for stopping, is an easing. Have this inside a script call command:


screen.pictures[1].rotate((x - screen.pictures[1].angle)/180)


x is the angle you want your picture to stop at.


This script call will make your picture get progressively slower, the closer it gets to the angle you want it to stop at.

Spoiler
FXCcBdx.png






If you want it to slow down faster then do this:
 


screen.pictures[1].rotate(((x - screen.pictures[1].angle)/180)*y)


y is a constant value of your choice. The bigger it is, the faster the picture will be reaching 0 velocity. If y is high enough, you can make the stop seem instantaneous.







DISCLAIMER: I'm not well acquainted with scripting yet, so there might be some less convoluted / more sophisticated ways to help you out. This is what I could figure out within my current knowledge and strength. With a little imagination, it has worked well for me. If someone more experienced would like to add something more, please feel free to.

Original thread: https://forums.rpgmakerweb.com/threads/rotate-picture-in-a-certain-angle.39077/