Subsz
(Sub)
April 13, 2023, 8:28am
#1
Trying to make a selection box
game.Players.LocalPlayer:GetMouse().Button1Down:Connect(function()
startSearching = true
local rel=workspace.CurrentCamera.CFrame:pointToObjectSpace(game.Players.LocalPlayer:GetMouse().Hit.Position)
pointBegin=Vector2.new(rel.x/-rel.z, rel.y/-rel.z)
boxStart = UIS:GetMouseLocation()
end)
UIS.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement and startSearching then
local currentPos = UIS:GetMouseLocation()
holderFrame.Top.Position = UDim2.fromOffset(boxStart.X,boxStart.Y)
holderFrame.Right.Position = UDim2.fromOffset(boxStart.X,currentPos.Y)
holderFrame.Bottom.Position = UDim2.fromOffset(currentPos.X,boxStart.Y)
holderFrame.Left.Position = UDim2.fromOffset(currentPos.X,currentPos.Y)
end
end)
how it functions atm
Subsz
(Sub)
April 13, 2023, 10:51am
#2
Fixed that, though now I have another question:
How would I detect what parts are in the selection box, given the 4 points of the rectangle?
nds_w
(NasaSatelite_Wifi)
April 13, 2023, 11:06am
#3
you can raycast every pixel where the gui is covering, if it is too laggy you can skip some pixels
11trat
(Trat)
April 13, 2023, 11:11am
#4
By comparing AbsolutePosition
.
Workspace:GetPartsInBox would work. Very performant. If
Subsz
(Sub)
April 13, 2023, 11:34am
#6
Well, to do that I need to create the part. My next question would be how would I create a part given 4 points on a 2D surface
Subsz
(Sub)
April 13, 2023, 11:34am
#7
I meant, 3D parts inside the UI
11trat
(Trat)
April 13, 2023, 11:37am
#8
There’s a ViewportPointToRay function
Ok then, you can make a 3d raycast using viewportPoint to ray function.
First divide up your selection box into 50 points(can be more or less, just more precise this way).
Then you take these 2d points and use @Tratium ’s viewportPointToRay function and get all the unit rays needed.
Then you loop through these unit rays and raycast them.
Subsz
(Sub)
April 13, 2023, 3:54pm
#10
Alright, so how do I divide it up into X amount of points ?
Take your 1st point(one in the left corner top)
Then take your 2nd point(one in the right corner bottom)
Lerp between your x values at an increment of 7.(could be anything)
Lerp between your y values at an increment of 7.
Iterate up to 7^2(49) and for each 7 switch to using a different y value.
Subsz
(Sub)
April 13, 2023, 7:08pm
#12
Would there be any other way? like perhaps forming a part based on the 4 points
Definitely it’s workspace:GetPartsInBox.
The 1st thing I suggested.
You don’t need a part, just a limit on how big, and a cframe origin of the box.
Subsz
(Sub)
May 6, 2023, 3:08pm
#14
How would I get the CFrame?