Author Topic: [SOLVED]Touch issues.  (Read 6410 times)

MaskedPixel

  • Guest
[SOLVED]Touch issues.
« on: May 02, 2012, 11:11:40 PM »
I am trying to cast a ray from a camera that is solely rendering ngui.  It is orthographic and it's size is 1(normal for ngui right?).  The problem I am having is converting screen coordinates to a ray with ScreenPointToRay.  The origin of the ray is always no more than 1 unit from the position of the camera in any direction.  If I have a collider lined up with where I want to check for the touch, how do I figure out if the collider is under the screen point?

This has to be done outside of NGUI events as I am testing for other gestures at the same time and the event queue is not processed at the right time for what I need to accomplish.  Otherwise, this would work great: http://www.tasharen.com/forum/index.php?topic=138.msg902#msg902

Sorry if this is a duplicate question...
« Last Edit: May 11, 2012, 11:41:31 AM by MaskedPixel »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Touch issues.
« Reply #1 on: May 03, 2012, 08:32:06 AM »
I'm not sure I understand the question. ScreenPointToRay gives you a ray. You then Raycast to determine what collider it hits.

MaskedPixel

  • Guest
Re: Touch issues.
« Reply #2 on: May 03, 2012, 09:54:12 AM »
I am trying to use ScreenPointToRay to cast a ray onto a UISprite with a BoxCollider attached.  Lets say the sprite is at (240, 350) which is the top right of the screen.  It draws in the correct position.  If i touch that sprite and use ScreenPointToRay, the ray's origin will be something like (1, 1, 0) and it's direction is (0, 0, 1).  That ray will not hit the collider.

How do I get the correct Ray?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Touch issues.
« Reply #3 on: May 03, 2012, 10:56:26 AM »
You're confusing world and local coordinates here. Your sprite is at 240x350 in local coordinates -- that is transform.localPosition. Now check its world coordinates via transform.position -- you will get completely different values -- values in 0-1 range.