Jump to content
Search Community

Forcing a clockwise rotation always - possible?

danee987 test
Moderator Tag

Recommended Posts

I searched around the forums but could not find any post that could help me so my apologies if it has been answered before. Basically I have a clock type arm that spins to different positions depending on what the user selects. It spins just like a clock arm, its pivot being at the end of the arm. Everything works fine except that the arm should only rotate clockwise, never counter-clockwise. So on some values the user selects the arm spins in the opposite direction, sometimes oddly enough even if the opposite direction is not the closest distance it will still spin that way.

 

I just need to always force it to spin clockwise no matter the value. Is there any way I can do this? Let me know thanks.

Link to comment
Share on other sites

Sure, the key here is to always make sure that the rotational value increases - it can go beyond 360 because visually there's no difference and Flash will adjust it internally anyway (Flash always reports rotational values as between 180 and -180).

 

For example, let's say your object's current rotation is 170 and your user clicks at a spot that reports as -170. If you do a normal tween from 170 to -170, that'll go backwards. So the key is to make sure the destination is always greater than the current value, so you can simply add 360 degrees if it's not.

 

if (targetRotation < currentRotation) {
   targetRotation += 360;
}
TweenLite.to(myObject, 1, {rotation:targetRotation});

 

See what I mean?

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...