Jump to content

Codepen Notification

You didn't provide a codepen sample that illustrates the problem. It really helps us quickly identify problems. This isn't mandatory, but it will get you better/faster results. Would you like to add one?

Forcing a clockwise rotation always - possible?

Started by danee987, May 02 2012 05:33 PM clockwise counter-clockwise rotation - - - - -

2 replies to this topic
danee987

Post #1 by danee987 , 02 May 2012 - 05:33 PM

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.
  • Back to top

GreenSock

Post #2 by GreenSock , 02 May 2012 - 06:15 PM

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?
  • Back to top

danee987

Post #3 by danee987 , 02 May 2012 - 07:28 PM

that was so amazingly simple. It works perfectly. lol. thanks!
  • Back to top




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

3rd Party Advertisement