I am trying to make a sort of drag selection system right now. I have a completely working dragger, but I am a little confused on how I should be able to get a list of 3d parts from what’s in the dragger.
local mouse = game.Players.LocalPlayer:GetMouse()
local selectorFrame
local oldPos
function mousePosition()
return UDim2.fromOffset(mouse.X,mouse.Y)
end
mouse.Button1Down:Connect(function()
oldPos = mousePosition()
selectorFrame = Instance.new("Frame",script.Parent)
selectorFrame.BackgroundTransparency = .5
selectorFrame.Position = oldPos
end)
mouse.Button1Up:Connect(function()
selectorFrame:Destroy()
end)
mouse.Move:Connect(function()
if selectorFrame then
selectorFrame.Size = mousePosition()-oldPos
end
end)
get the viewport position of every part via Camera:WorldToViewportPoint and check if they are within the 2D bounding box.
Convert the 2D bounding box to a 3D box and use spatial query via workspace:GetPartsInPart with an arbitrary Z length to find all intersecting parts.
The difference between these two methods is the first one only takes into account the center of each part, while the latter will consider parts that simply intersect the bounding box.
I didn’t know about the screenpoint function, but I read your code and took some notes. I’m thinking of so many things that I quit on because I didn’t know about this. Thanks you!
Always, ALWAYS read the damn documentation! Go save yourself hours of effort by using something Roblox has already made instead of making them yourself from scratch. I cannot stress this enough.
For example, I just discovered this Camera method a few weeks ago:
And these new math stuff for Vector3s ported over from the scalar math library