# How to implement smooth wandering on an annulus?

I am creating a 2D action platformer and want to create some steering behavior for a mage enemy.

Basically, I want the mage to smoothly wander inside an annulus centered on my player.

Below is an image depicting an example path the mage could follow.

The enemy currently has simple seek behavior. It simply accelerates toward whatever is set as its target.

I tried choosing a random target point in the annulus every so often, but when you do this, the enemy sometimes drifts across the center of the annulus to reach a point chosen on the other side.

So my question is, how can I achieve the desired movement?

If you are using steering behaviors to guide your objects, you could add a repellant force in the center of the circle.

A repellant force is a vector that points in the direction from the center of the circle to the object. The length of the vector is in inverse relation to the distance of the object from the cente (closer: bigger force, distant near zero force). You can tweak the repellant strength to suit your needs.

Give your mage a movement direction vector. When mage moves, turn it around slowly - this will give you wiggling movement. If mage goes outside of allowed range, or gets close to it, turn direction vector towards the center. If it gets too close, turn it away from center. Depending on how fast and how often you change direction vector, you may get the loops like on your image.

First let me preface this by saying, I think there's a better way to approach this problem by using a different metric (i.e. something like using polar coordinates rather than euclidean X,Y coordinates).

That said, using standard X,Y coords, the easiest way I can see to approach this problem is a test and reject pattern: