I have a circle and I click on somewhere in the circle, I want another smaller circle to go there when I do.
If I click out of the circle however, the magnitude should clamp and return the Vector2 on the circumference of the circle from the origin of the circle.
Here’s a function I wrote if someone knows wats wrong I’d like to know:
local function getClosestBounds(pX, pY)
local pXY = Vector2.new(pX, pY)
local relativeLen = (pXY - circle.AbsolutePosition).Magnitude
local clampedLen = math.clamp(relativeLen, 0, circle.AbsoluteSize.X)
local alpha = clampedLen / relativeLen
return pXY:Lerp(circle.AbsolutePosition, alpha)
end
To account for the offset you need to add the radius.
local function getClosestBounds(pX, pY)
local pXY = Vector2.new(pX, pY)
local centre = circle.AbsolutePosition + (circle.AbsoluteSize / 2)
local relativeLen = (pXY - centre).Magnitude
local clampedLen = math.clamp(relativeLen, 0, circle.AbsoluteSize.X / 2)
local alpha = clampedLen / relativeLen
return centre:Lerp(pXY, alpha)
end
This works however strangely it doesn’t clamp at the circumference along the bottom side of the circle, it’s like the lerp is shorter than it should be
Hey (@Waffloid is a cutie)
After some ponderin and deep self reflectance I figured it out, offsettin the Y value by negative 30 and subtractin both the returned Lerp X and Y values by the Parent component’s AbsolutePosition X and Y values, I found that it functions perfectly. The explanation my friend came up for this is that because of the topbar, ScreenGuis set positions relative. It’d seem that even though my ScreenGui instance has IgnoreGuiInset enabled, this behaviour is ignorant of it.