Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: silversteez on November 20, 2012, 07:52:35 PM

Title: 360 degree rotation
Post by: silversteez 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.

Title: Re: 360 degree rotation
Post by: ArenMook 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);
Title: Re: 360 degree rotation
Post by: fredxxx123 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?
Title: Re: 360 degree rotation
Post by: ArenMook 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.
Title: Re: 360 degree rotation
Post by: fredxxx123 on December 10, 2012, 09:30:27 PM
okay, i got it.
thx  :)
Title: Re: 360 degree rotation
Post by: gamesonytablet 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.
Title: Re: 360 degree rotation
Post by: nah0y 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 :)
Title: Re: 360 degree rotation
Post by: pheinz 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
Title: Re: 360 degree rotation
Post by: ArenMook 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.
Title: Re: 360 degree rotation
Post by: nah0y 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);
Title: Re: 360 degree rotation
Post by: pheinz 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