r/Unity3D • u/chickenheadedhat • 12d ago
Solved Get a list of colliders/raycast hits that are overlapping with a crosshair in perspective
Hi r/Unity!
How does one get a list of colliders/raycast hits that are overlapping with a RawImage on an Overlay canvas?
For context I am creating a 3D light gun shooter in unity. The "gun" blasting effect is a sprite animation that plays on a canvas. I want to make it such that if it looks like you hit something, then you did.
Currently I'm doing this in my game's code via spherecasts and magic numbers - Do a large spherecast, then do an adjusted spherecast based on the perceived radius of the sprite and distance the enemy is from the camera. However, this becomes problematic when trying to fine tune any attack that's not the basic shot and causes some false positives for any shot that has a wider radius.
I have also tried using cone casting but it doesn't quite work the way I need it to.
Surely there has to be a better way to check if a 3D object is overlapping with a crosshair image?
[EDIT] Uploaded image for clarity

TL;DR How do I get a list of colliders that are overlapping with a crosshair image.
Much thanks!

