Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Check if *ANY PART* of a UI reticle overlaps a gameobject?

Discussion in 'Editor & General Support' started by Big_Friggin_Al, May 13, 2020.

  1. Big_Friggin_Al

    Big_Friggin_Al

    Joined:
    Jan 9, 2014
    Posts:
    36
    I know I can raycast from the camera to tell if the very center of a reticle is overlapping a world gameobject, but that doesn't tell me about whether the rest of the reticle shape overlaps anything.

    I also know I can world->screen the vertices from the gameobject's bounds, and then check that rectangle for overlap, but that gives false positives in the 'gaps' between parts of the gameobject that stick out (as the bounds encompass the entire shape, empty space and all).

    Is there a way to check whether any part of a large UI reticle image is overlapping any part of a specified gameobject, without false positives?
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    Is it a perspective camera or orthographic? If it's orthographic you can do a physics.SphereCast.
     
  3. Big_Friggin_Al

    Big_Friggin_Al

    Joined:
    Jan 9, 2014
    Posts:
    36
    Perspective, so that won't work (but thank you for the suggestion!)