currently I have a building system that relies on the mouse for moving buildings. however I need to make changed to the build system so now I need the mouse to both ignore the model its dragging AND ignore specific parts it hovers over. unfortunately mouse.TargetFilter only filters one instance so now I need to make a customized mouse to substitute the current mouse system. I tried this:
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
function managecustommouse()
local ray = Ray.new(game.Workspace.CurrentCamera.CFrame.p,mouse.Hit.p)
local parts = workspace:FindPartOnRay(ray)
print(parts)
end
mouse.Move:Connect(function()
managecustommouse()
end)
this does not work quite as expected, it only prints nil unless my camera is directly under my character in which case it prints parts of my character. am I doing something wrong?
Credit to @realhigbead, he made this. Use CollectionService:AddTag(part)
local coll = game:GetService('CollectionService')
local function getMousePosition(mouse)
local ray = Ray.new(mouse.Origin.p,mouse.UnitRay.Direction*2048)
local ignore = coll:GetTagged('TargetIgnore')
ignore[#ignore+1] = plr.Character
local _,pos = workspace:FindPartOnRayWithIgnoreList(ray,ignore)
return pos
end
can you show me how? I have some of it hooked up and Im trying to print the object the ray finds as a test before tagging things to filter:
local coll = game:GetService('CollectionService')
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local function getMousePosition(mouse)
local ray = Ray.new(mouse.Origin.p,mouse.UnitRay.Direction*2048)
local ignore = coll:GetTagged('TargetIgnore')
ignore[#ignore+1] = plr.Character
local _,pos = workspace:FindPartOnRayWithIgnoreList(ray,ignore)
return pos
end
function printpos()
getMousePosition(mouse)
print(mouse)
end
mouse.Move:Connect(function()
printpos()
end)
local coll = game:GetService('CollectionService')
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local function getMousePosition(mouse)
local ray = Ray.new(mouse.Origin.p,mouse.UnitRay.Direction*2048)
local ignore = coll:GetTagged('TargetIgnore')
ignore[#ignore+1] = plr.Character
local _,pos = workspace:FindPartOnRayWithIgnoreList(ray,ignore)
return pos
end
function printpos()
local mousePos = getMousePosition(mouse)
print(mousePos.X, mousePos.Y, mousePos.Z)
end
mouse.Move:Connect(function()
printpos()
end)
Seems like you already have a solution working here and from the standpoint of simplicity it’s probably your best bet.
However, I’ll take the opportunity to plug my mouse module. You can then use it like so for your purposes.
local mouse = require(game.ReplicatedStorage.Mouse).new()
function mouse:IgnoreCheck(hit, position, normal, material)
-- return true if you want to ignore the part
-- this is just an example:
return hit:IsDescendantOf(hover_model) or hit.Transparency >= 1
end
Then you could use all the other aspects of the mouse you know and love with the comfort of knowing the conditions you outline will be ignored.