Right, my bad! I did do a bit more diving into this issue and recalled some forgotten knowledge.
Alright, so I did try creating my own raycast code to check this problem out. One change I did make was using the HumanoidRootPart instead since that’s canonically a lot more stable if you need to run some kind of position-bound game logic rather than something visual.
With relatively the same math applied as you, one of the results I got was that the raycast would always occur if the terrain cells were in the front left corner of my character. This in mind it helps me to narrow down the potential cause and that would be the calculation involved for direction.
With only the first parts of the calculation.
Since direction is often confused as an endpoint instead of a relative vector, I had a go by only using Vector3.new(0, 10, 0)
which appropriately casted 10 studs down relative to my HumanoidRootPart. This means that the direction calculations can use some changes based on that.
In truth having paid attention I probably could’ve seen the issue a while back. Knowing that the direction is already relative to your origin, you don’t need to specify it again! Just take out the head.Position part from your directional calculation and that should resolve it.
If you need a point of reference and a test file, here’s what I used:
TerrainDetectRepro.rbxl (27.9 KB)
Have a walk around and see which material gets printed to your console. Check Camera in the Workspace for the visualisers, you may need to size them up to see more clearly what they’re hitting. Example below when I sized them up to (2, 2, 2).
tl;dr:
Direction is already relative to origin, so get rid of the head.Position bit of your direction math. Just extend the LookVector out 30 and then subtract 10 from the Y axis to lower the detection point.
(head.CFrame.LookVector * 30) - Vector3.new(0, 10, 0)