I’m attempting to create a selection tool using Raycast to determine whether or not a Part is selected:
Mouse.Button1Down:Connect(function()
local Target = API.Raycast(Camera.CFrame.p, Mouse.Hit.p)
if Target ~= nil then
print("Yes")
else
print("No")
end
end)
--||--||--||--
API.Raycast = function(Origin, Direction)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {TriTerrain}
raycastParams.FilterType = Enum.RaycastFilterType.Whitelist
local raycastResult = game:GetService("Workspace"):Raycast(Origin, Direction, raycastParams)
if raycastResult then
if raycastResult.Instance ~= nil then
return raycastResult.Instance
end
end
end
The reason I’m doing this is so that the Mouse ignores any obstructions in the way and selects what is needed -
However, this doesn’t seem to work as the Mouse.Hit.p is stopping wherever the obstruction is.
How can I work around this or extend the direction of the Ray to bypass the obstruction and register the part?