Author Topic: 360 degree rotation  (Read 14403 times)

silversteez

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
    • MattSilverstein.com
360 degree rotation
« on: November 20, 2012, 07:52:35 PM »
i know this is a probably really easy, but i can't figure it out...

i have a TweenRotation on a sprite that i want to rotate 359.9 degrees clockwise and then loop. is this possible? what To and From values should i use?

currently any To value greater than 180 causes the sprite to rotate less rather than more.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 360 degree rotation
« Reply #1 on: November 21, 2012, 01:43:08 AM »
Don't use TweenRotation for this. You need to do your own turning logic: something like Quaternion.Euler(0f, Time.deltaTime * 180f, 0f);

fredxxx123

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: 360 degree rotation
« Reply #2 on: December 10, 2012, 08:05:06 AM »
I try to changed ..
  1.    cachedTransform.localRotation = Quaternion.Slerp(Quaternion.Euler(from), Quaternion.Euler(to), factor);
To
  1.    cachedTransform.localRotation = Quaternion.Euler(Vector3.Slerp(from, to, factor));

It's a bad idea?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 360 degree rotation
« Reply #3 on: December 10, 2012, 12:22:54 PM »
Yes, it's a bad idea. You're interpolating floats here which will give you a very different result. Interpolating a quaternion rotation from -360 to 1 degree will result in 1 degree of rotation. Interpolating a vector from -360 to 1 will result in 361 degrees of rotation.

Like I said, create your own tween script. Don't modify NGUI's tweening.

fredxxx123

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: 360 degree rotation
« Reply #4 on: December 10, 2012, 09:30:27 PM »
okay, i got it.
thx  :)

gamesonytablet

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: 360 degree rotation
« Reply #5 on: December 11, 2012, 08:20:48 AM »
Hi,

I use NGUI/Examples/Scripts/Other/Spin.cs for this and it works perfectly fine.  8)

Maybe give it a try, since it's easy as just attaching to what you want to spin and play around with the Rotation speed x,y,z which are the only parameters there are.

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: 360 degree rotation
« Reply #6 on: December 13, 2012, 04:45:32 AM »
Don't use TweenRotation for this. You need to do your own turning logic: something like Quaternion.Euler(0f, Time.deltaTime * 180f, 0f);

Why not add that TweenQuaternion to NGUI by default?
I think it's not the first topic on this subject I see and people may need it :)

pheinz

  • Guest
Re: 360 degree rotation
« Reply #7 on: January 29, 2013, 07:31:10 AM »
Hi - I'm trying to spin a "radar sweep" which is a simple sprite. No matter what I use - Spin.cs, Quaternion.Euler, Rotate, etc... The sprite hovers right around 3 degrees of rotation. It seems as though something is holding the rotation to 0 and my attempts to rotate get applied once before it goes back to 0.

This sprite is in a UIPanel. Any ideas?

Thanks,
Phil

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 360 degree rotation
« Reply #8 on: January 29, 2013, 05:44:48 PM »
All I can suggest is find that "something". There is no magic, and NGUI won't rotate anything for you. Whatever it is, you're doing it.

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: 360 degree rotation
« Reply #9 on: January 30, 2013, 03:45:07 AM »
Just use a script with this in the Update method :
mTransform.RotateAroundLocal(Vector3.forward, mRotationSpeed * Time.deltaTime);

pheinz

  • Guest
Re: 360 degree rotation
« Reply #10 on: January 30, 2013, 07:46:04 AM »
I appreciate your reply!  I found the something. I was controlling it from another component in my last project and I did not take that control out.

I have been a GUI programmer for 30+ years. My company has decided to go 3D for all future business apps. I am finding NGUI to be an indispensable tool - so powerful and flexible.

Thanks again,

Phil