I am trying to do a raycast to search for a specific object and don’t want to do it again in the same position.
Basically like this:
- You start on a single point
0
- Then if nothing hits the ray, expand the search
-1 0 1
-1 .. 1
-1 0 1
- Keep expanding the search until the object is found
-2 -1 0 1 2
-2 . . . . . 2
-2 . . . . . 2
-2 -1 0 1 2
My idea was to put the for loops in a while loop
Add a local variable that counts every time the loops are finished
Put it in the start and end value of the for loop
Then stop once the “radius” gets too big
local cycle = 0
while cycle < 16 do
cycle += 1
for y = -cycle, cycle, cycle*2 do
for x = -cycle, cycle, cycle*2 do
end
end
end
But this will only search in an X pattern, not a square.
Any suggestions on how I could do that?