I have a problem creating mechanics for a game.
In the attached file, you need to click on the buttons to move the colored objects, according to their proximity, always giving preference to the blue one. Whenever you click a button, the system has to identify which of the two objects is closest to it and send it to the base closest to that button. It started working well but then it stopped moving the objects and sometimes sent the object to a completely different path.
I did it another way, but the code was too long and I'm trying to cut it down.
Could anyone help me solve this mechanic?
Thanks in advance
we.tl/t-vtycEuQAxF
EDITED: Objective of the game: move the objects, removing the red ones in front of the blue one (there will be many scattered across the screen) until the blue one reaches the end. There is a movement limi, but I just want to solve the mechanics.