Try this:
Let's assume you want to rotate an object "Stick".
Give Stick a boolean: Stick.Rotating and set it to false.
Declare variable Stick.Rot_Time = x (where x is the time you want the stick to take to rotate 360 degrees).
Declare Stick.Start_Angle = Stick.Angle (the starting angle, in case it's not zero).
Then, when you want to rotate the Stick, set Stick.Rotating = True and use the following code:
- Code: Select all
If Stick.Rotating = True:
> Trigger once: Set Stick.Start_Angle to Stick_Angle
> Set Stick.Angle to Stick.Angle + (360 * dt / Stick.Rot_Time) -- this will rotate clockwise, use a minus to rotate anti-clockwise
> If Stick.Angle is within 2 degrees of Stick.Start_angle -- this stops the stick at 1 rotation**
>-> Set Stick.Rotating to False
>-> Set Stick.Angle to Stick.Start_Angle
** It won't work if you want it to rotate in less than 1.5 seconds because that is 4 degrees per tick at 60 fps. If the rotation rate is any faster and/or the framerate drops then it could miss this check window and carry on spinning. If that happens, just use a wider window...
An alternative would be to have a look at the plugins - you could use Rex's Rotate To plugin for this as well.