I want to get some points that wrap around an object, similar to how the Scale tool in Roblox Studio wraps its points around the part we select. I’ve written the following function to achieve it:
for foo, point in ipairs(points:GetChildren()) do
local adjustment = Vector3.zero
if point:HasTag("PosXPoint") then
adjustment = Vector3.new(target.Size.X / 2 + 1.5, 0, 0)
elseif point:HasTag("PosYPoint") then
adjustment = Vector3.new(0, target.Size.Y / 2 + 1.5, 0)
elseif point:HasTag("PosZPoint") then
adjustment = Vector3.new(0, 0, target.Size.Z / 2 + 1.5)
elseif point:HasTag("NegXPoint") then
adjustment = Vector3.new(-target.Size.X / 2 - 1.5, 0, 0)
elseif point:HasTag("NegYPoint") then
adjustment = Vector3.new(0, -target.Size.Y / 2 - 1.5, 0)
elseif point:HasTag("NegZPoint") then
adjustment = Vector3.new(0, 0, -target.Size.Z / 2 - 1.5)
else
error("Point did not have an expected tag")
end
point:PivotTo(target:GetPivot() + adjustment)
end
It works, but I’m not very happy about how much boilerplate (ie. the fact that the only difference between each case is the coordinate and the sign of target.Size.Coordinate / 2 + 1.5
) I have written and I’m wondering if there’s a way to achieve the same effect with less code?