Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Fliperamma on August 21, 2014, 12:53:41 AM

Title: [NOT SOLVED] UIGrids - Smooth Tween causing Spring Position to never complete
Post by: Fliperamma on August 21, 2014, 12:53:41 AM
Hi!

I'm developing a solitaire card game using UIGrids and Smooth Tween to change the cards from one UIGrid to another.
Sometimes, when I do the reparenting, some Cards have their Spring Position active for ever, with the position changing constantly but with very very small values (visually imperceptible)...

I've put a Log to track it down and found that it was not getting in to the "enabled = false;" line... (ex. 2.328306E-15 >= 1.392746E-10 == false):
  1. // line 96 of SpringPosition Class
  2. if (mThreshold == 0f) mThreshold = (target - mTrans.localPosition).sqrMagnitude * 0.00001f;
  3. mTrans.localPosition = NGUIMath.SpringLerp(mTrans.localPosition, target, strength, delta);
  4.  
  5. if (mThreshold >= (target - mTrans.localPosition).sqrMagnitude)
  6. {
  7.         mTrans.localPosition = target;
  8.         NotifyListeners();
  9.         enabled = false;
  10. }
  11.  


To solve it I'm checking if the local positions are different before applying the Spring Position in the UIGrid Class (If the positions are the same, there's no need to animate them)
> "&& Vector3.SqrMagnitude(t.localPosition - pos) >= 0.0001f"

  1. // Line 369 of UIGrid.cs
  2. if (animateSmoothly && Application.isPlaying && Vector3.SqrMagnitude(t.localPosition - pos) >= 0.0001f)
  3. {
  4.         SpringPosition sp = SpringPosition.Begin(t.gameObject, pos, 15f);
  5.         sp.updateScrollView = true;
  6.         sp.ignoreTimeScale = true;
  7. }
  8. else t.localPosition = pos;
  9.  

Solved my problem.. Any chance to have this (or something like that) in the next update?

Thanks
Title: Re: [SOLVED] UIGrids - Smooth Tween causing Spring Position to never complete
Post by: ArenMook on August 22, 2014, 03:16:49 AM
Certanly. I'll add your change to the repository.
Title: Re: [SOLVED] UIGrids - Smooth Tween causing Spring Position to never complete
Post by: Fliperamma on July 15, 2015, 07:45:53 PM
Yeap.. this post is OLD but this bug aged well :)

Can you please take a look / update this fix? I've just got the exact same problem again ... and fixed it again with the code that I've posted before ;)

Thanks
Title: Re: [NOT SOLVED] UIGrids - Smooth Tween causing Spring Position to never complete
Post by: ArenMook on July 16, 2015, 11:08:49 AM
Hmm... wonder if I overwrote it at some point... I'll add it back in, thanks.