Perhaps it’s closer than you think and your raycast is already starting beyond it. Add an extra line that does RaycastAll() and use Debug.Log() to print out what all that ray passes through.
If you only care about one specific Collider, you can use the form of raycast that starts form that Collider.
Raycasting, colliders, planes, Plane, etc:
There are many types of 3D raycasts.
One is the generic Physics one: hits anything in the scene
Another is one that lives on a collider.
If you know which collider you care about, you can use that collider instance to see if a ray hits it.
That way you not only know that it hit, but because you are already asking "Did anything hit this collider?" you also know what collider it is.
These are some of the types of 3D raycasts:
https://docs.unity3d.com/ScriptReference/Physics.Raycast.htm…
You can get rays from the camera at a given spot, so one approach is to cast rays from the camera corners and make sure they hit your terrain, or hit your terrain bounding box.
To ignore screen pixel dimensions and just get the corner rays, this is the API you want:
The nice part is that it doesn’t matter how your camera is set, how your field of view is set, etc., It just works.
You can use this to raycast and hit physics on your ground using:
asks “did I hit any collider in the scene?…
Epoch! I always love your posts because you’re always working on the next thing. Awesome.
So for this I would pick a random spot from left to right at the top of your screen, then raycast down to “hit” the terrain and see how high it is at that point, and from that you can emplace your missile above the ground, or on a pedestal or whatever.
Remember there are various flavors of Raycast in Physics2D:
https://docs.unity3d.com/ScriptReference/Physics2D.Raycast.html
“Tell me if I hit any 2D col…