I was playing around with raycasts, and I wanted to detect the terrain under a bunch of parts.Turns out that for some reason, the raycasts sometimes misses the terrain completely.
I investigated this issue, and it turns out the misses aren’t just random, they occur in a specific pattern - the outlines of square chunks around 128 studs wide (see picture to understand what I mean).
Another thing I find very strange about this is that this only occurs in places that have hills. On flat areas it works fine and never misses.
Below is the script I used to create what you can see on the image. Basically it creates parts on a bunch of different places, each part fires a raycast downwards, if it finds something nothing happens with it, but if it doesn’t find something (misses the terrain), it turns red and gets the neon material. (To be clear, the image is how it looks when the script has finished running.)
local XStart = -200
local XEnd = 200
local ZStart = -200
local ZEnd = 200
local samplePart = Instance.new("Part")
samplePart.Size = Vector3.new(2,2,2)
samplePart.Transparency = 0.7
samplePart.Material = Enum.Material.SmoothPlastic
samplePart.Anchored = true
for xPos = XStart, XEnd, 1 do
for zPos = ZStart, ZEnd, 1 do
local newPart = samplePart:Clone()
newPart.Position = Vector3.new(xPos*4, 45, zPos*4)
local terrainCheck = Ray.new(newPart.Position, Vector3.new(0, -100, 0))
local hit, p, _, m = workspace:FindPartOnRay(terrainCheck)
if not hit then
newPart.Color = Color3.new(1, 0, 0)
newPart.Material = Enum.Material.Neon
newPart.Transparency = 0
end
newPart.Parent = workspace
end
wait()
end
You can see that where there are hills, there are red cubes organized in a pattern, every red cube indicates that it couldn’t detect the terrain below it.
Any idea why this is occuring?
Are you starting the ray inside the mountains? Why don’t you increase the height to more than 45 studs?
I am not, the ray is started from the part’s position which is well over the terrain surface, I have tried putting the parts higher up but no difference.
Can replicate this issue. As far as I know some beta feature was causing it and it seems that now the feature has been fully released. Seems that the raycasts don’t work completely on terrain region bounds.