I do raycasting a lot, and i think that you shouldn’t really use a table to separate what your raycast will detect. using FilterDescendantsInstances for folders is better if you may ask me
local paints = workshop.Debris
mouse.Move:Connect(function()
if isMouseOnHold and isEquipped then
local ro = workspace.CurrentCamera.CFrame.Position
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {paints} -- you can add character in here if you want separate them from the raycast too
local raycastResults = workspace:Raycast(ro, mouse.UnitRay.Direction*1000, raycastParams)
if raycastResults then
local p = Instance.new("Part", workspace.Debris)
p.Size = Vector3.new(1,0.25,1)
p.Anchored = true
p.CFrame = getAngleBetween(p.CFrame.UpVector, raycastResults.Normal, ro)
p.Position = mouse.Hit.Position
p.CanCollide = false
end
end
end)
local mouse = game.Players.LocalPlayer:GetMouse()
local isMouseOnHold = false
local isEquipped = false
function getAngleBetween(u, v, axis)
local dot, uxv = u:Dot(v), u:Cross(v)
if dot < -0.99999 then return CFrame.fromAxisAngle(axis, math.pi) end
return CFrame.new(0,0,0, uxv.x, uxv.y, uxv.z, 1+dot)
end
script.Parent.Unequipped:Connect(function()
isEquipped = false
end)
script.Parent.Equipped:Connect(function()
isEquipped = true
mouse.Button1Down:Connect(function()
isMouseOnHold = true
end)
mouse.Button1Up:Connect(function()
isMouseOnHold = false
end)
end)
local paints = workspace.Debris
mouse.Move:Connect(function()
if isMouseOnHold and isEquipped then
local ro = workspace.CurrentCamera.CFrame.Position
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {paints} -- you can add character in here if you want separate them from the raycast too
local raycastResults = workspace:Raycast(ro, mouse.UnitRay.Direction*1000, raycastParams)
if raycastResults then
local p = Instance.new("Part", workspace.Debris)
p.Size = Vector3.new(1,0.25,1)
p.Anchored = true
p.CFrame = getAngleBetween(p.CFrame.UpVector, raycastResults.Normal, ro)
p.Position = raycastResults.Position
p.CanCollide = false
end
end
end)
nvm i fixed it, the p.position is using the mouse position
local mouse = game.Players.LocalPlayer:GetMouse()
local isMouseOnHold = false
local isEquipped = false
function getAngleBetween(u, v, axis)
local dot, uxv = u:Dot(v), u:Cross(v)
if dot < -0.99999 then return CFrame.fromAxisAngle(axis, math.pi) end
return CFrame.new(0,0,0, uxv.x, uxv.y, uxv.z, 1+dot)
end
script.Parent.Unequipped:Connect(function()
isEquipped = false
end)
script.Parent.Equipped:Connect(function()
isEquipped = true
mouse.Button1Down:Connect(function()
isMouseOnHold = true
end)
mouse.Button1Up:Connect(function()
isMouseOnHold = false
end)
end)
local paints = {}
mouse.Move:Connect(function()
if isMouseOnHold and isEquipped then
local ro = workspace.CurrentCamera.CFrame.Position
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = paints
local raycastResults = workspace:Raycast(ro, mouse.UnitRay.Direction*1000, raycastParams)
if raycastResults and not ( raycastResults.Instance:HasTag("Paint") ) then
local p = Instance.new("Part", workspace.Debris)
p.Size = Vector3.new(1,0.25,1)
p.Anchored = true
p.CFrame = getAngleBetween(p.CFrame.UpVector, raycastResults.Normal, ro)
p.Position = mouse.Hit.Position
p.CanCollide = false
p:AddTag("Paint")
end
end
end)