I’m currently not at my PC to give an example.
However, I have a Minimap / Radar that I’ve been working on that pinpoints both the Players location and others, converts the Position to Udim2 and then displays on a GUI.
I’m currently using UICornerRadius to keep the UI circular however the RadarPoints go out of the circular bounds - I’m looking for a way to clamp the Points to the boundary?
You can use some math to determine the maximum position of the UI. You can use trigonometry, distance math and or the formula for a circle, or use a Vector2 (of the distance from the center of the circle) on which you clamp the magnitude (maximum magnitude from center is equal to the radius of the circle)
I don’t know how you calculate the position of your radar, so it’s hard to really give insight into how to add clamping as ideally that logic can be added directly to the calculation for the position
Anyway, code for clamping Vector2 magnitude should be something like this
local Radius = 150 -- Pixels?
-- If magnitude is smaller than Radius, do not change Vector
-- If magnitude is above Radius, get the Unit vector (magnitude of 1), and multiply it by Radius, which will give you a point at the max allowed distance
local Vector = Vector.Magnitude <= Radius and Vector or Vector.Unit*Radius
Server:GetService('RunService').PreRender:Connect(function(dt, ...)
-- Getting the radius of the circle. The radius is the maximum magnitude convertedOffset will be allowed to have
local Radius = self.Circle.AbsoluteSize.X/2 -- Can also use Y, as both are the same size
for __,Part in (Server:GetService('CollectionService'):GetTagged('Part')) do
local convertedOffset = getOffset(Part) * 2
local radarPoint = RadarPoints[__]
if (Part.Position - self.HumanoidRootPart.Position).Magnitude < 50 then
radarPoint.Visible = true
else
radarPoint.Visible = false
end
-- Limit the magnitude of convertedOffset to Radius
convertedOffset = convertedOffset.Magnitude <= Radius and convertedOffset or convertedOffset.Unit*Radius
radarPoint.Position = UDim2.new(0.5, convertedOffset.X, 0.5, convertedOffset.Y)
end
updateRadar(...)
end)
The way your code works is perfect for adding clamping, just had to add those two lines where I put the comments, inside the RunService loop