How to clamp UDim2 scale positions within a circle?

I want to know how to clamp only the Scale property of UDim2 within a circle, like instead of using the Offset property I want to use the Scale.

bump

1 Like

Is the circle positioned at (0,0)?
Is the scale going to be relative to a square, or is it relative to the player’s screen?

2 Likes

The circle is not positioned at (0,0) (why’d you ask? not to be rude)
The scale is relative to the player’s screen, if youre talking about what the circle is parented under

I had a reason, then forgot.

As it makes use of scale instead of offset, it’s a bit more difficult to calculate. I’ll give it a try at least.

1 Like

Another thing I should check:
Is the circle directly parented to a screen GUI, or is it parented to a frame / another UI element?
This’ll affect which properties i can use.

2 Likes

the circle is parented directly under a screen gui

1 Like

Had to deal with other matters for a few hours, so sorry for a later reply that is simply asking for more information.

Are you able to please provide a place with the relevent UI (just the circle component), just so I have something available for testing that I know accurately reflects your scenario.

1 Like

What do you mean by clamping the scale within a circle? You can parent a frame within a frame and scale it to {1, 0}, {1, 0} in order to cover the whole frame.

1 Like

here, apologies for taking so long as well

basically i’m trying to make a radar ui system, and the map part usually relies on udim scaling to work on all screens, using offset wouldn’t work

clamp.rbxl (66.3 KB)

i mean clamping the udim2 positions but instead of using the offset property, i use the scale property.

i mean scale as in the properties of the udim2

That use case explains why you wanted it to clamp! I’ll see what I can do.

offset would still be ideal, and looking at your code you are using RenderStepped to update the map regularly. Is it fine if I end up using Offset to get the desired effect (it won’t matter what screensize the player has, don’t worry)

1 Like

oh yeah, the code in that place file is just a more simplified version of the code i have, so there aren’t really 2 rendersteppeds btw

Spent longer than intended on it, because it turns out I had written X when I meant to write Y ;/

Here’s how I ended up clamping it:

local magnitude = math.sqrt(final.X^2 + final.Y^2)/2
local maxDistance = 0.25
if magnitude > 0.25 then
	local scale = maxDistance/magnitude
	position = UDim2.fromScale(.5 + (final.X / 2)*scale, .5 + (final.Y / 2)*scale)
end

clamped.rbxl (66.1 KB)

2 Likes

thank you so much, do you mind explaining a little bit of what’s going?

i already understood the magnitude vector part, but why is .25 there?

The 0.25 was just a value I got from trial and error, used to determine where the edge of the circle is.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.