Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Meltdown on August 25, 2017, 02:15:50 AM

Title: Move sprite from one UI element position to another with TweenPosition
Post by: Meltdown on August 25, 2017, 02:15:50 AM
I'm struggling with this for some reason.

I have a TweenPosition component on my tutorial pointer arrow, and I'm trying to indicate to my user that they need to drag the one UI element, onto the other.

I've tried using...

  1. pointerTweenPosition.from = new Vector3(startElementTransform.localPosition.x, startElementTransform.localPosition.y, startElementTransform.localPosition.z);
  2. pointerTweenPosition.to = new Vector3(endElementTransform.localPosition.x, endElementTransform.localPosition.y, endElementTransform.localPosition.z);
  3. pointerTweenPosition.PlayForward();
  4.  

and

  1. pointerTweenPosition.from = UICamera.currentCamera.ScreenToWorldPoint(new Vector3(startElementTransform.localPosition.x, startElementTransform.localPosition.y, startElementTransform.localPosition.z));
  2. pointerTweenPosition.to = UICamera.currentCamera.ScreenToWorldPoint(new Vector3(endElementTransform.localPosition.x, endElementTransform.localPosition.y, endElementTransform.localPosition.z));
  3. pointerTweenPosition.PlayForward();
  4.  

But neither work properly. The pointer never appears in the right place.
Whats the easiest way to get this working properly?

Thanks
Title: Re: Move sprite from one UI element position to another with TweenPosition
Post by: ArenMook on August 25, 2017, 08:58:10 PM
The reason this doesn't work is the coordinates you're feeding are wrong. Local position is always relative to whatever widget you're using. Unless the two widgets are siblings, that will mean completely different coordinates. World position (screen to world point) should not be used either. The tween expects local coordinates relative to the object being tweened. You need to transform them properly.

from = pointerTweenPosition.transform.parent.InverseTransform(startingElementTransform.position);
Title: Re: Move sprite from one UI element position to another with TweenPosition
Post by: Meltdown on August 25, 2017, 10:57:21 PM
Thanks that did the trick  :)

I used InverseTransformPoint (InverseTransform doesn't exist)

  1. from = pointerTweenPosition.transform.parent.InverseTransformPoint(startingElementTransform.position);
  2.