For your object you have three property. The center of the object (x,y) and the width.
To know if two square overlay it’s easy. With a simple if you can know it:
if((math.abs(square1.x-square2.x)\<=(square1.width+square2.width)/2) and (math.abs(square1.y-square2.y)\<=(square1.width+square2.width)/2)) object overlay
Are you searching for a way to find the best location for the object if it’s outside the screen or over an other object ?
If it’s what you are looking for, here is the code for the most logical location of your object
testinbatiment is finger position ancienxvalide is the old x of the autorise localisation ancienyvalide is the old y of the autorise location local distancemin=(testinbatiment.x-ancienxvalide)\*(testinbatiment.x-ancienxvalide)+(testinbatiment.y-ancienyvalide)\*(testinbatiment.y-ancienyvalide)-- distance between you finger and the previous object localisation if distancemin\>1000 then -- if the distance is a bit big local limitex1carre=ancienxvalide -- define limits to find a logical place for the object local limitex2carre=testinbatiment.x local limitey1carre=ancienyvalide local limitey2carre=testinbatiment.y local minx=limitex1carre local maxx=limitex2carre if minx\>maxx then maxx=limitex1carre minx=limitex2carre end maxx=maxx+60 minx=minx-60 local miny=limitey1carre local maxy=limitey2carre if miny\>maxy then miny=limitey2carre maxy=limitey1carre end maxy=maxy+60 miny=miny-60 local testposbat={} testposbat.x=minx testposbat.y=miny local varrandx=mathfloor((maxx-minx)\*0.2) if varrandx\<10 then -- max precision require varrandx=10 end local varrandy=mathfloor((maxy-miny)\*0.2) if varrandy\<10 then varrandy=10 end while testposbat.x\<maxx do while testposbat.y\<maxy do local distancemintest=(testinbatiment.x-testposbat.x)\*(testinbatiment.x-testposbat.x)+(testinbatiment.y-testposbat.y)\*(testinbatiment.y-testposbat.y) if distancemin\>distancemintest then local autorise1=autorisefunction(testposbat) --verify if the location is autorise if autorise1==0 then distancemin=distancemintest ancienxvalide=testposbat.x ancienyvalide=testposbat.y end end testposbat.y=testposbat.y+varrandy end testposbat.y=miny testposbat.x=testposbat.x+varrandx end end