Collision with Camera and Mouse

Can somebody tell me how to stop parts colliding with camera and mouse

  1. Colliding with camera: I want walls and other parts not to stop the camera from zooming too far.

  2. Colliding with mouse: I want to make it so that when I click a Click Detector through another part, the click detector triggers.

Please note that I want it to be so that only some blocks do this, preferably using tags.

Can someone tell me how to do this? I tried using Collision Groups but didn’t know how.

1 Like

Umm… I sent this 12 hours ago but still no reply. Please somebody tell how.

  1. To disable camera collisions, the easiest way would be overwriting Roblox’s default camera controller. To do this, just click Test in Roblox Studio and find “PlayerModule” under your player’s PlayerScripts and copy it to clipboard:

    Once you’ve done that, quit the test server and paste it into StarterPlayerScripts (make sure not to change the names of anything). Then find [PlayerModule -> CameraModule -> ZoomController -> Popper] and open the script. Then scroll down to about line 197, find the function canOcclude(part) and change it to include your own custom condition like so:
local function canOcclude(part)
	return
		getTotalTransparency(part) < 0.25 and
		(FFlagUserRaycastUpdateAPI or part.CanCollide) and
		subjectRoot ~= (part:GetRootPart() or part) and
		not part:IsA("TrussPart") and 
		not part:HasTag("YourTagNameHere")
end
  1. Removing “mouse collisions” is a bit trickier. Even parts that are fully transparent and excluded from the mouse’s TargetFilter will still block a ClickDetector from being activated. Your best bet might be to fire a ray from the player’s camera to their mouse hit position:
local CollectionService = game:GetService("CollectionService")
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local mouse = player:GetMouse()
local maxClickDistance = 100 --Change to your heart's content

mouse.Button1Down:Connect(function()
	local raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.Include
	raycastParams.FilterDescendantsInstances = CollectionService:GetTagged("ClickTag")
	
	local origin = camera.CFrame.Position
	local direction = (mouse.Hit.Position - origin).Unit
	
	local raycastResult = workspace:Raycast(origin, direction * maxClickDistance, raycastParams)
	
	if raycastResult then
		local partClicked = raycastResult.Instance
		--Do whatever else
	end
end)

This approach works, but it doesn’t use an actual ClickDetector and is all handled locally, meaning you’ll have to communicate to the server every time the part is clicked. Anyways, I hope this all helps and I wish you the best of luck on your endeavors.

2 Likes

Thank you I’ll try that. :smiley:

(I can’t try right now cause my net pretty bad.)

1 Like

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