Is there a way for mouse.target to ignore certain parts?

I have a placement grid system which I use what square the player is hovering over and add it by 4 spaces. I have previews too, but the system thinks that the preview is a part and it tries to the get side of that. I tried to just do that if its name was “Preview” then it would return, but this results in a lot of lag. Is there a non laggy way to do this?

The TargetFilter property is used for this. If you need more than one filter, you will have to capture the target yourself via raycasting. It isn’t hard to do. If you need more than 1 filter, I’d be glad to show a raycast example.

3 Likes

Do you raycast the maximum 5000 studs or shorter? I feel like raycasting 5000 studs a lot could be very resource intensive.

Only as far as needed. Sometimes just 100

Could you do an example with raycast please?

Here’s a snippet from my Mouse module:

local RAY_DISTANCE = 500

function Mouse:GetRay(distance)
	local mousePos = userInput:GetMouseLocation()
	local viewportMouseRay = cam:ViewportPointToRay(mousePos.X, mousePos.Y)
	return Ray.new(viewportMouseRay.Origin, viewportMouseRay.Direction * distance)
end

function Mouse:Cast(ignoreDescendantsInstance, terrainCellsAreCubes, ignoreWater)
	return workspace:FindPartOnRay(self:GetRay(RAY_DISTANCE), ignoreDescendantsInstance, terrainCellsAreCubes, ignoreWater)
end

function Mouse:CastWithIgnoreList(ignoreDescendantsTable, terrainCellsAreCubes, ignoreWater)
	return workspace:FindPartOnRayWithIgnoreList(self:GetRay(RAY_DISTANCE), ignoreDescendantsTable, terrainCellsAreCubes, ignoreWater)
end

function Mouse:CastWithWhitelist(whitelistDescendantsTable, ignoreWater)
	return workspace:FindPartOnRayWithWhitelist(self:GetRay(RAY_DISTANCE), whitelistDescendantsTable, ignoreWater)
end
3 Likes