Author Topic: Last Touch Position  (Read 6016 times)

Moradom

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 15
    • View Profile
Last Touch Position
« on: January 23, 2014, 01:00:44 AM »
Hello,

I am using an NGUI widget as a spell bar for a mobile game. This is what I am trying to do:

1. The widget is listening for a touch to start within its collider, for this I am using OnPress(true)
2. For the user to cast the spell the touch will need to be dragged off the widget's collider. I am using hoveredObject to determine when the game object's tag changes
3. Once step 2 happens I want to spawn a gameObject (Non-NGUI object)  at the location lastTouchPosition (using PoolManager5 to spawn object, so the object is spawned as a child of my pool manager which is a child of UIRoot)
4. I want the gameObject to follow the touch until OnPress(false)

The problem I am having is step 3 and 4

Is lastTouchPosition is a screen point or a world point? I am assuming screen point. So I am trying to get this to local space.

I take the lastTouchPosition and convert it to a Vector3 and do ScreenToWorldPoint using the UICamera. Then I do transform.InverseTransformPoint and set this value to my spawned object's transform position. My spawned object is way…I mean way out in space. I am confused on how this all works, am I on the right path? I also tried doing this with UICamera.lastHit.point and it is still not working.

Also can I use OnDrag(delta) to have the gameObject follow the touch? I would just add the delta values to the gameObject's transform.

I would appreciate any guidance or suggestions.

Thank you!
 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Last Touch Position
« Reply #1 on: January 23, 2014, 05:39:35 AM »
UICamera.lastTouchPosition is a Vector2, so it wouldn't be possible for it to be a world position.

UICamera.lastHit.point gives you the world position.

The pressed object will keep receiving OnDrag() notifications until you release the button.

Moradom

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 15
    • View Profile
Re: Last Touch Position
« Reply #2 on: January 23, 2014, 11:48:34 AM »
I was pretty tired last night, but yes I would agree lastTouchPosition would not be a world position!  :-\

The problem I am having is not really an NGUI problem at this point, it is my lack of understanding how to spawn objects in different coordinate systems. I will continue to experiement.