Author Topic: Move sprite from one UI element position to another with TweenPosition  (Read 1844 times)

Meltdown

  • Jr. Member
  • **
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 56
    • View Profile
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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Move sprite from one UI element position to another with TweenPosition
« Reply #1 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);

Meltdown

  • Jr. Member
  • **
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 56
    • View Profile
Re: Move sprite from one UI element position to another with TweenPosition
« Reply #2 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.