Author Topic: Possible UIDraggablePanel RestrictWithinBounds bug when resetting position  (Read 6149 times)

seandanger

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 32
    • View Profile
    • Bit By Bit Studios
I have a vertically-oriented UIDraggablePanel in my scene.  After dragging the contents downward, they snap back up into position as expected.  There is a minor problem though, as the calculated position the DraggablePanel moves back toward is slightly higher than it was previously, each time.  This result is my panel has a "resting position" many pixels above its original resting position.  Ideally, it would not do this and instead go no higher than its original position (which in my case, is y == 0.0f).

Here's a small video demonstrating it, sorry for the blurriness, but you should get the idea: http://www.youtube.com/watch?v=PFQFwgxhilA

I'll look into a workaround for now, just wanted to see if anyone knew about it or if ArenMook was working on it, or if I possibly have my panel setup incorrectly.  I'll update if I find my own fix.

@Aren So far, it looks like the problem comes from SpringPanel over-shooting the panel's position when it returns.

EDIT: The opposite also happens when dragging the panel beyond its upper limits so that it snaps back down slightly too far each time.
« Last Edit: August 22, 2012, 06:53:49 PM by seandanger »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Hmm... That's odd. Try changing SpringPanel line 56 from:

  1. if (mThreshold >= (target - mTrans.localPosition).magnitude) enabled = false;
to:
  1. if (mThreshold >= (target - mTrans.localPosition).magnitude)
  2. {
  3.         mTrans.localPosition = target;
  4.         enabled = false;
  5. }

seandanger

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 32
    • View Profile
    • Bit By Bit Studios
That's the code I already have there.  I believe I'm using v2.1.0.

I think I was wrong about SpringPanel overshooting it's target, since that localPosition = target line is there, but in UIDraggablePanel line 237, inside RestrictWithinBounds, with:

  1. SpringPanel.Begin(mPanel.gameObject, mTrans.localPosition + constraint, 13f);

mTrans.localPosition.y slowly increases.  I don't see how it's doing that when the localPos is getting set to the target when SpringPanel ends.

EDIT: It must be that, initially, the target is being calculated with some extra added.  Note that if I change the RestrictWithinBounds() call at line 621 to pass true instead of false, it snaps back to the proper position each time.
« Last Edit: August 22, 2012, 11:29:52 PM by seandanger »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Aha, the clip doesnt get adjusted properly. Try this:
  1.         void Update ()
  2.         {
  3.                 float delta = UpdateRealTimeDelta();
  4.  
  5.                 if (mThreshold == 0f) mThreshold = (target - mTrans.localPosition).magnitude * 0.005f;
  6.  
  7.                 Vector3 before = mTrans.localPosition;
  8.                 Vector3 after = NGUIMath.SpringLerp(mTrans.localPosition, target, strength, delta);
  9.  
  10.                 if (mThreshold >= Vector3.Magnitude(after - target))
  11.                 {
  12.                         after = target;
  13.                         enabled = false;
  14.                 }
  15.                 mTrans.localPosition = after;
  16.  
  17.                 Vector3 offset = after - before;
  18.                 Vector4 cr = mPanel.clipRange;
  19.                 cr.x -= offset.x;
  20.                 cr.y -= offset.y;
  21.                 mPanel.clipRange = cr;
  22.  
  23.                 if (mDrag != null) mDrag.UpdateScrollbars(false);
  24.         }

seandanger

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 32
    • View Profile
    • Bit By Bit Studios
Beautiful :)

I know it was a silly little issue, but it was coming into play a lot after running the game for awhile.  Thanks so much!