Author Topic: Can use a bit of help on casting a ray.  (Read 1805 times)

JSorrentino

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Can use a bit of help on casting a ray.
« on: June 05, 2014, 11:18:40 PM »
  1.         Collider2D[] results = new Collider2D[10];
  2.         void RaycastForHits()
  3.         {
  4.                 int hits = Physics2D.OverlapCircleNonAlloc(col.center, 0.5f, results);
  5.                 Debug.Log(hits + " hits");
  6.         }
  7.  

When a 2d collider is touched (OnPress), I am trying to cast a ray from the center of that collider (2d circle), to see if any other objects (of the same type that triggerd the raycast) overlap.  I'm sure I'm doing something wrong, and can use a hand.  I'm getting erratic results.

Also, I need to set the radius of the ray cast to match the size of the collider (same one used above as col.center).

Any help appreciated.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Can use a bit of help on casting a ray.
« Reply #1 on: June 06, 2014, 02:39:58 AM »
Non-alloc API is brand-new, and has bugs in it, so I can't comment on this at all. Try using a simple Physics2D.OverlapPointAll instead like NGUI does in UICamera's Raycast function.

JSorrentino

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: Can use a bit of help on casting a ray.
« Reply #2 on: June 06, 2014, 09:57:41 AM »
Disregard, sleep helps, apparently licking windows was my thing of the day.

Sorry to waste your time, Aren.
« Last Edit: June 06, 2014, 10:41:15 AM by JSorrentino »