How to disable CanQuery for collidable parts

Hello everyone! So I am currently developing a top-down game however I have encountered a pretty massive game design issue.

As the camera is top-down, some walls will get in the way of the camera.

Now, my solution to this is to get all parts obscuring targets and make them the target filter of the mouse.

Code:

-- LocalScript
local Player = game.Players.LocalPlayer
local Mouse =  Player:GetMouse()
local RunService = game:GetService('RunService')

-- Dictionary to remember parts that was made transparent
local rememberedParts = {}

-- Variable needed to keep track of when remembered parts is not obscuring anymore
local iterationCount = 0

RunService.RenderStepped:Connect(function(dt)
	iterationCount = iterationCount + 1

	local castPoints = { 
		Player.Character:WaitForChild('HumanoidRootPart').Position, 
		Player.Character.Head.Position, 
		Player.Character["Right Arm"], 
		Player.Character["Left Arm"]
	}

	local ignoreList = {}
	for _, i in ipairs(game.Players:GetChildren()) do
		table.insert(ignoreList, i.Character)
	end

	local arr = workspace.CurrentCamera:GetPartsObscuringTarget(castPoints, ignoreList)

	-- Loop though all obscuring parts
	for _, m in pairs(arr) do
		-- Is this a 'not marked before' part,
		if rememberedParts[m] == nil then
			-- then add it to the rememberedParts, with data containing its original transparency
			rememberedParts[m] = { origTransparency = m.Transparency }
			-- and make it transparent only once.
			m.Transparency = 1
			Mouse.TargetFilter = m
		end
		-- Need to update this 'remembered part', as it was (again) obscuring the player
		rememberedParts[m].stillObscuring = iterationCount
	end

	-- Loop through all the 'remembered parts',
	for m, data in pairs(rememberedParts) do
		-- if this part was not updated this time around,
		if data.stillObscuring < iterationCount then
			-- then change its transparency back to normal
			m.Transparency = data.origTransparency
			-- and remove it from the remembered parts dictionary
			rememberedParts[m] = nil
		end
	end
	
end)

However, this is still a failed fix due to these reasons:

Mouse.TargetFilter can only ignore 1 part.
Sometimes it doesn’t work at all, or, multiple parts are obscuring the target.

Is there any way to disable canquery for these parts while still retaining collidability to prevent player from falling out of the map?

I do not want to add “fall preventers” which just teleports the player back to the map when falling, as this ruins immersion and is very annoying.

ever thought about setting the DevCameraOcclusionMode?

Didnt work for me. maximum of 3o characters

Sorry, my bad. I just realized canquery can be set to false even with cancollide on if we just do it in code, I assumed it was impossible since it wasn’t doable in properties.

Sorry guys!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.