Probably there is... try figuring out yourself first ok?
Ok, thanks for your help.
Develop games in your browser. Powerful, performant & highly capable.
To get rid of the infinity loop: Create a value that need to be 0 in order to teleport, is set to one when you teleport, and is set to 0 again when you don't overlap any of the portal.
To not get stuck in a wall i've temporary changed it so that you klick out the portals wherever you want. I also limited it to just one portal of each color.