Search Unity

Question Raycast Game Object detection issue

Discussion in '2D' started by donnayye, Mar 20, 2023.

  1. donnayye

    donnayye

    Joined:
    Sep 29, 2022
    Posts:
    1
    For some reason, my raycast does not detect game Object collision when I click on the Object. It always 'misses'. I've tried creating a "Clickable" Layer to the Game Object and assigned it via script with the physic.raycast and still does not work.

    The origin and direction coordinate would output origin: (x,y, -1.70) and dir: (0,0,1)

    Could it be that the raycast origin / direction is not in the correct z-coordinate? I am new to Unity and game designing. The purpose of the my game design is to have user react to the stimulus object and include the accuracy based on the # of Taps (missed/hit).

    Im not sure where I am going wrong with the scripting process. I looked at many forums and tried many different ways. I dont want to use the void MouseDown() function since it is limited.
    Here is the code I programmed and attached to the game object:
    upload_2023-3-19_19-11-26.png
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,499
    This is the 2D forum but you're asking about 3D physics. The Physics forum is here. I can move your post if you wish.

    If you're using 2D physics then use Physic2D.OverlapPoint.

    Please use code-tags when posting code and not plain-text or screenshots.

    Thanks.