Skip to content

Instantly share code, notes, and snippets.

@ecurtiss
Last active August 1, 2021 03:27
Show Gist options
  • Save ecurtiss/4a9dea0d470b4e70e9b1456bf1a2483d to your computer and use it in GitHub Desktop.
Save ecurtiss/4a9dea0d470b4e70e9b1456bf1a2483d to your computer and use it in GitHub Desktop.
Shrinks the hover box in Roblox Studio when you get closer to it
local CoreGui = game:GetService("CoreGui")
local MIN_THICKNESS = 0.001
local MAX_THICKNESS = 0.04
local MIN_DIST = 2
local MAX_DIST = 10
game:GetService("RunService").Heartbeat:Connect(function()
local hoverBox = CoreGui:FindFirstChild("HoverBox")
if hoverBox and hoverBox:IsA("SelectionBox") then
local adornee = hoverBox.Adornee
if adornee then
local position
if adornee:IsA("BasePart") then
position = adornee.Position
elseif adornee:IsA("Model") then
local primaryPart = adornee.PrimaryPart
if primaryPart then
position = primaryPart.Position
else
local part = adornee:FindFirstChildWhichIsA("BasePart", true)
if part then
position = part.Position
end
end
elseif adornee:IsA("WeldConstraint") or adornee:IsA("NoCollisionConstraint") then
position = adornee.Part0.Position
end
if position then
local camDist = (workspace.CurrentCamera.CFrame.Position - position).Magnitude
local thickness = MIN_THICKNESS + (MAX_THICKNESS - MIN_THICKNESS) * math.clamp((camDist - MIN_DIST) / (MAX_DIST - MIN_DIST), 0, 1)
if hoverBox.LineThickness ~= thickness then
hoverBox.LineThickness = thickness
end
end
end
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment