Skip to main content
2 of 6
revised answer, because missed important detail of question answered via comments

Check X any Y boundaries for the respective objects.

![visualization of x,y boundaries that need checking][1] [1]: https://i.sstatic.net/NWw7e.png

So, basically you want your object's X value to be be greater than RED's X value and less than BLUE's X value (so it's horizontally between them), and your object's Y value to be less than the max Y value RED/BLUE (whichever has a greater Y, less than that). When it passes the lower Y value then you note that it passed that and wait for it to pass the greater Y value.

To roll your own here will take a little thinking, particularly if the goal posts (the RED/BLUE objects move) and especially if they move independently. If they are always fixed (game of marbles) when checking this stuff then you can test to see whether they are vertical or horizontal first and have slightly different sets of checks.

Because these are spheres, you either have to track two X values and two Y values (respective straight line edges) or calculate those two values from the coordinates of the sphere's center and it's radius.