Need help to raycast onto a 2D sprite on a 3D Environment!

I’m struggling with finding a way to raycast onto this sprite on the map. The camera mode is in perspective.
The reason why I would like to use 2D raycasting is to take advantage of the polygon collider component. I was wondering if this was possible. Thank you!
7897744--1005907--upload_2022-2-15_4-13-15.png

In 2D, you don’t raycast into the screen really, you preferrably use Physics2D.OverlapPoint which is quicker and exists in 2D. You’ll obviously need to be careful that the 2D world positon is calculated using the real Z position of the Transform if you’re using Perspective projection on the Camera.

There is the ability to perform a pseudo raycast in/out of the screen (Physics2D.GetRayIntersection) but it isn’t a 3D raycast because there’s no support for 3D raycast in 2D onto the “faces” of colliders as they don’t exist. What this does is project the 3D ray into 2D, perform that 2D raycast then sort the results in the order the ray is projected. Much more complex and expensive than a simple OverlapPoint but it works.

NOTE: There’s a dedicated Physics forum you can use here too.

Thank you for the response, I was able to get Physics2D.OverlapPoint to work in orthographic. I’m not sure what you mean by setting the Z axis though. You can only input Vector2 according to the tooltip.

You were talking about Perspective mode, not Othographic. In that mode, the Z position you specify when converting a mouse position to a world position is very important. In Orthographic it doesn’t matter.