Making the AI cycle through all it's the waypoints

I actually did not use mod arithmetic to solve this, I created a private var CurrentIndex and the length of the PatrolPoints array and I just check if my index is out of range to reset it to the first element.

Then the selector will run every time and check if our index has gone through all the waypoints to start from the beginning.

I think this is the better way of doing it too, and I ended up using the same way. Modulus is a pretty expensive operation, but granted it won’t be the bottleneck unless you’re running it multiple times every frame (which this is not). The only thing I see in your function is the false execution node is unnecessary, since you’re just reassigning the value to itself.

Privacy & Terms