Okay so I can help here I think. I made this function which does exactly what you want, and can even make bound checks along just 2 axis like you need as well.
See the thread:
Okay so I can help here I think. I made this function which does exactly what you want, and can even make bound checks along just 2 axis like you need as well.
See the thread: