mouse.Move:Connect(function()
local ray,point,surfaceNormal,material = game.Workspace:FindPartOnRayWithIgnoreList(mouse.UnitRay,{Enum.Material.Air})
print(material)
end)
The "FindPartOnRayWithIgnoreList" is what you were looking for.
Also just found the possible reason why Enum.Material.Air does not work for an ignore list, it is set to not browsable https://wiki.roblox.com/index.php?title=API:Class_reference/ReflectionMetadata
I came up with another idea, but it didn't work, I'll put the code here anyway (it does work for other applications)
I made a region3 from the camera's position to the mouse position and used Terrain:ReadVoxels() to get the terrain along the path of the ray, but the problem in this case is that Enum.Material.Air is not able to be detected by ReadVoxels
mouse.TargetFilter = workspace.Part
function ignoreList(first,last)
local region = Region3.new(last, first)
print(region.CFrame," SIZE ",region.Size)
workspace.Part.CFrame=region.CFrame
region = region:ExpandToGrid(4)
local material,occupancy = game.Workspace.Terrain:ReadVoxels(region, 4)
local size = material.Size
local allMats = {}
for x = 1, size.X do
for y = 1, size.Y do
for z = 1, size.Z do
allMats[#allMats+1]=material[x][y][z]
end
end
end
return allMats
end
5 comments
That yields an "Unable to cast value to Object" error
I know, I'm currently trying to figure out why it's doing that, but I'm assuming it has something to do with using the mouse.UnitRay
the main problem is that "Air" is not an object. It has no parent so we don't know how to reference it
oh I see
But this is still a creative way to get the material of the terrain, even if we can't get past the air