Overlap in raycast causing issues

Like you saw in the videos, the raycast prints the wrong object because of the overlap. I already tried to use mouse.Target and other raycast methods but it doesn’t seem to make a difference. I saw that you can use a part in the camera position then use GetPartInParts, but i want to know if there is any easier or simpler method or the part method is the only one i can use. Ty:)

The raycast i used.

RS.RenderStepped:Connect(function(dT)
	
	local ray = Ray.new(camera.CFrame.Position, camera.CFrame.LookVector * range)
	local model, position = workspace:FindPartOnRay(ray, player.Character)

you can just use the .Include ray type of RaycastParams and put it as the third argument in your Ray.new function to only include the mouse target.

edit: nevermind, use workspace:Raycast, since Ray.new does not have a third argument. it works basically the same way as your current system does.

Already tried and it’s the same result :l

    local origin = camera.CFrame.Position
	local direction = (m.Hit.Position - origin).Unit * range
	local params = RaycastParams.new()
	params.FilterDescendantsInstances = {m.Target}
	params.FilterType = Enum.RaycastFilterType.Include
	local result = workspace:Raycast(origin, direction, params)
	local model
	if result and result.Instance then
		model = result.Instance
	end

mouse.target is actually very inaccurate since i tested a system like this a while ago. a unperformant idea but would work: emit a raycast from the camera to the mouse position, then store model as the result. that’s what worked for me.

Nevermind, the issue was caused by a variable that i was using.

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