Help with a Spherecast Excluding Terrain Which Is Not Water

Hello, thank you for taking the time to read my post.

  1. What do I want to achieve?
    I have a spherecast set up, and I want it to detect parts inside of terrain while using Enum.RaycastFilterType.Include for my raycast parameters.

  2. What is the issue?
    Everything in my scripts works. The issue I am running into is filtering objects to detect/not detect with my Spherecast. I have a pretty basic setup thus far.

Localscript:

local detector = script.Parent

print(detector.Origin.Position)

detector.Equipped:Connect(function()
	repeat
		detectorModule.doSpherecast(player, detector)
		task.wait(5)
	until detector.Parent ~= player.Character
end)

detector.Unequipped:Connect(function()
	print("The tool has been put away")
end)

Detector is a tool that I created. My goal is to have it detect landmines hidden within parts of the map covered with terrain. When the detector is equipped, it runs this function inside of a ModuleScript.

-- Define parameters for the spherecast to detect
local mineDetectParams = RaycastParams.new()
mineDetectParams.FilterType = Enum.RaycastFilterType.Include

function DetectModule.doSpherecast(player, detector)
	-- Get the landmines to use in detection
	local mineFolder = workspace.Landmines:GetChildren()
	
	mineDetectParams.FilterDescendantsInstances = {mineFolder}
	
	task.wait(.2)
	local castOrigin = detector.Origin.Position
	
	-- Define Constants for the Spherecast
	local CAST_RADIUS = 25
	local DIRECTION_OF_CAST = ((detector.Origin.Position - Vector3.new(0, 10, 0)) - detector.Origin.Position)
	
	local sphereCast = workspace:Spherecast(castOrigin, CAST_RADIUS, DIRECTION_OF_CAST, mineDetectParams)
	print(sphereCast)
end

It basically just creates a Spherecast at a specific part within the tool that moves downward through the map. It all works. However, I began to ran into issues when I experimented with better filtering options.

I originally tried to use

Enum.RaycastFilterType.Exclude

but I soon realized that excluded so many objects would not be very intuitive, as there would be a LOT to exclude.

I soon shifted my focus to using “Include”, and as stated above, only included the parts inside of a created folder. However, my Spherecast script no longer detects the parts when they are inside of terrain.

I guess I am asking for some suggestions of other filtering methods I could try. Maybe what would be the most efficient method for excluding terrain in general. I never figured out how to do that with actual terrain, and not just water.

  1. What solutions have I tried thus far.

I am honestly unsure of how to “fix” this without refactoring my entire system. I tried researching the Spherecast and WorldRoot pages on the documentation, but their filtering information is not entirely perfect.

Any help is greatly appreciated, thanks in advance.

Sphere cast as in a ball? Wouldn’t you need to use shape cast instead of raycast?

I was not familiar with the exact lingo. I just wanted to say (in case people reading did not know what a Spherecast was) that it was basically the same method as a Raycast. It is a shapecast, a

workspace:Spherecast()

Actually, after reading back I see what you mean. I changed the title.