# How can I detect if a frame is touching another frame?

Hello,

I’m creating a gui with moving frames similar to GTAs Datacrack.

I have the frames to move but am unable to figure out how to detect if a frame is touching another frame. Here’s a video of this system in action.

https://gyazo.com/c9d4a0a10e904a95f2d94f312d551bdc

I did my best to show what I’m trying to say. Basically, the moving frame if they aren’t touching the red bar in the middle. It would cancel the tweens and make a fail gui appear. How can I accomplish this? If you are able to help, it’s greatly appreciated. If not, have a great rest of your day!

I think you need to check the position of the red stripe. And if the grey thing is on the position of the red line then …

I agree with you, the problem is I have no idea how to even go about that.

You can make an area in your script with Position and when the grey frame is in that specific area then …

I kinda get what you’re saying, but I don’t know how I would script once the player clicks and then scripting the detecting the frames position.

Maybe you can make that the Frame must be between 2 positions on for example the Y-axis.

For this there isn’t much you have to do. To determine whether or not one of the grey bars are intersecting the red (this is assuming that there is no rotation whatsoever and you only care if they intersect vertically) all you have to do is determine their Y position and see if it’s below or above the red line.

So, to determine if the grey bar is above all you have to do is see if the grey bars bottom is above the top of the red line. For determining if it is below, check if the grey bars top is below the red lines bottom. If both of these are false it is intersecting.

Okay interesting, when I asked this question before, there was a lot of complex math that was involved to determine the position of the grey frames and red line. Will there be more complex math or should it be simple?

Given there is no rotation it definitely is not complex. You just need the AbsolutePosition and AbsoluteSize of both the grey and red lines: Although you’ll only be using the Y components of both of these. You can use both of these to determine the top and bottom of both lines and then you can use what I said above to determine if it is intersecting (the math is just simply adding and subtracting half the AbsoluteSize.Y from the AbsolutePosition.Y).