Skip to main content
gamedev.net
🔒 Locked

Circular looping

Started by SeeForever 2 replies 1.3k views
Original Post
SeeForever
SeeForever
Greetings, I need to borrow this loop from someone, as my brain crashes every time I try to find an answer (in other words, I can't think of anything but a bunch of inefficient 'for' loops). explanation I want the dark blue smiley to find the location of the closest light blue smiley using the pattern shown with the yellow line. Thanks in advance.
nb
nb
how about setting-up a 2d bounding box that you do forward collision checks on.. and when you faceplant into a wall you move the opposite wall behind you an increment in your direction, then turn right, then wash rinse repeat until you either stand on the target or have no more space to move.
ToohrVyk
ToohrVyk
The movement pattern is:

R 1, U 1, L 2, D 2, R 3, U 3, L 4, D 4, R 5 ...

Simply store your state as a triple (dir, n, i) with the transition rules:

(R, n, 0) → (U, n, n)
(L, n, 0) → (D, n, n)
(U, n, 0) → (L, n+1, n+1)
(D, n, 0) → (R, n+1, n+1)
(dir, n, i) → move dir ; (dir, n, i - 1)

Simply keep applying the transition rule until you've found the target.
SeeForever
SeeForever
That movement pattern inside a do-loop did the trick.

Thanks very much!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.