How to filter some parts with Camera:ScreenPointToRay()

You can write your topic however you want, but you need to answer these questions:

Hi, I would like to know how I would filter parts with Camera:ScreenPointToRay().

Basically what im trying to do is use the mouse screen position and get the 3d position from it but filter out some models.

local function getMouse3dPos(inputObject: InputObject) --similar to mouse.hit.p but better
    local mousepos = inputObject.Position
	
    local cameraRay = Camera:ScreenPointToRay(mousepos.X, mousepos.Y)
---@diagnostic disable-next-line: redundant-parameter
	
	
	local RaycastParamsThing = RaycastParams.new({table.unpack(PagfamGunData.RaycastPartFilter), character:GetDescendants(), Camera:GetDescendants()}, Enum.RaycastFilterType.Exclude, PagfamGunData.FilterWater)

    local raycastResult = workspace:Raycast(cameraRay.Origin, cameraRay.Direction * PagfamGunData.RayLength, RaycastParamsThing)

	raycastResult = raycastResult ~= nil and raycastResult.Position or cameraRay.Origin + cameraRay.Direction * PagfamGunData.RayLength --if there wasn't any instance to hit then it will simply return the destination's position

	return raycastResult

I am looking for any solutions or alternatives (other than using Mouse.Hit since it only filters out one instance) would be great. Thanks for leaving any insights to this problem.

2 Likes

Actually nvm, I realized that canQuery existed…

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