Author Topic: angle of a touch from the centerpoint of a sprite  (Read 3514 times)

vajoiner

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
angle of a touch from the centerpoint of a sprite
« on: November 09, 2016, 11:02:40 AM »
how does one get the angle of a touch from the center point of a sprite? i can only seem to get the angle from the 0,0 of the cameras lasteventposition, not objects

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: angle of a touch from the centerpoint of a sprite
« Reply #1 on: November 09, 2016, 12:36:19 PM »
Just use math. You know your touch position in screen space. Get the UI camera via NGUITools.FindCameraForLayer(widget.gameObject.layer), use cam.ScreenToWorldSpace to convert that to world, then widget.transform.InverseTransformPoint(pos) to convert it to local coordinates to your widget. Sin/cos to find your angle, depending on what you need. This isn't an NGUI question but a math question.

vajoiner

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: angle of a touch from the centerpoint of a sprite
« Reply #2 on: November 10, 2016, 10:44:42 PM »
ok i will work on this. i have the math using rad2deg*atan2 etc. but confused on how to get the touch point for single sprites using the camera. thank you