Hello.
I'm in the process of making a RTS game in Roblox, but I've came up with an issue.
Making it short, I'm currently scripting a selection box UI. I've got it ready; it's like the Windows right click dragging that forms that blue rectangle box.
However, after detecting that the user has lifted their mouse left button and it is ready to detect units inside of the rectangle, I have came unable to be able to list these.
Does anybody have any idea how I could do this?
I've got this so far, but of course it doesn't work.
local xS = script.Parent.Selection.Position.X.Offset
if script.Parent.Selection.Size.X.Offset < 0 then
xS = xS - math.abs(script.Parent.Selection.Size.X.Offset)
end
local xE = script.Parent.Selection.Position.X.Offset
if script.Parent.Selection.Size.X.Offset > 0 then
xE = xE + script.Parent.Selection.Size.X.Offset
end
local yS = script.Parent.Selection.Position.Y.Offset
if script.Parent.Selection.Size.Y.Offset < 0 then
yS = yS - math.abs(script.Parent.Selection.Size.Y.Offset)
end
local yE = script.Parent.Selection.Position.Y.Offset
if script.Parent.Selection.Size.Y.Offset > 0 then
yE = yE + script.Parent.Selection.Size.Y.Offset
end
local castPoints = {}
print(xS)
print(xE)
warn(yS)
warn(yE)
for x = xS, xE do for y = yS, yE do
table.insert(castPoints, Vector3.new(x, y, 0))
end end
local objs = workspace.CurrentCamera:GetPartsObscuringTarget(castPoints, { })
for i, v in pairs(objs) do
print(v.Name)
end

1 comment
The best I can come up with at the moment is looking in to https://developer.roblox.com/api-reference/function/Camera/ScreenPointToRay and then doing some maths to work out intersection in a shape.