How Would I Check If a Gui Element Is Outside of the Frame it is In, like it is not touching the Frame
If any of you know the how to do this please comment how to below I really need this for a ui library i’m making.
How Would I Check If a Gui Element Is Outside of the Frame it is In, like it is not touching the Frame
If any of you know the how to do this please comment how to below I really need this for a ui library i’m making.
you could just to a function to check if vector 2 is inside a region 2 made up of 2 vector 2’s.
Like this.
function isinregion2(point, pos, size)
if point.X > pos.X and point.X < pos.X + size.X and point.Y > pos.Y and point.Y < pos.Y + size.Y then
return true
end
return false
end
and from there on its fairly simple.
One way you could go about this is by checking AbsolutePosition magnitudes. You could also look at EgoMoose’s 2D Collision Detection tutorial.
Thanks i’m just really bad at math and can’t find anything really about this and am tired, but thanks a lot.
Is there a way to do this with UDim2 instead of Vector2 just wondering
Yes, Udim2
’s Offset (arguments) are in pixels and since Vector2
s are just 2d vectors, you can use them to define positions in pixels, which means switching from vector2 to Udim2 is as simple as utilizing the offset of Udim2:
Example:
local pos = Vector2.new(20,20)
You can do:
Udim2.new(0,pos.x,0,pos.y)
Also since I’m guessing you are talking about using Udim2 for positioning something, as long as your vector2 calculations are meant to be used in pixels and there isn’t any scaling going on then just using offset works just fine.
This also means that you can primarily use Udim2
for your collsion calculations. However, I would personally recommend sticking to vector2 for that (of course you have to still use udim2 too, for positioning) as it’s usually simpler and more compressive to read especially if you are not going to use the scale arguments(x,y) at all.