Hi, I wanted to share with you all a little thing I've been working on. This is a bit of AI for moving an object in a circle.

It works much like AIUpdateTrain. You use one waypoint, which goes at the centre of the circle. O_WAYPOINTSPEED is the same as usual, but I've used O_WAYPOINTFLIP to set the direction of motion (0 = clockwise, 1 = anti) - try setting an Action Object to switch it!

I've also added another variable O_WAYPOINTRADIUS, which you'll have to add a #def for. It does what it says on the tin. You'll probably want to set it to the same as the seperation between the starting positions on the map, but the AI will correct it anyway. Again, try changing it with an Action object.

Code: Select all

```
func AIUpdateCircle( idx )
{
if(idx==-1) return;
if(ObjGet(idx,O_DISABLE)) return;
if(!IsUpdate(ObjGet(idx,O_DELAY))) return;
if(ObjGet(idx,O_STATUS)!=1) return;
id2 = ObjGet(idx,O_TARGET);
if(id2==0) return;
idx2 = ObjFind(id2);
if(idx2==-1) return;
speed = ObjGet(idx2,O_WAYPOINTSPEED);
clock = ObjGet(idx2,O_WAYPOINTFLIP);
radius = ObjGet(idx2,O_WAYPOINTRADIUS);
rad = (float)radius;
x2 = ObjGet(idx2,O_ X) ;
y2 = ObjGet(idx2,O_Y);
x = ObjGet(idx,O_ X) ;
y = ObjGet(idx,O_Y);
count = 0;
label:
if(speed - count==0)
{
ObjSet(idx,O_X,x);
ObjSet(idx,O_Y,y);
return;
}
else
{
if(clock==0){ if(y>y2){ xt = x - 1;}
if(y<=y2){ xt = x + 1;}
if(x>=x2){ yt = y + 1;}
if(x<x2){ yt = y - 1;} }
if(clock==1){ if(y>=y2){ xt = x + 1;}
if(y<y2){ xt = x - 1;}
if(x>x2){ yt = y - 1;}
if(x<=x2){ yt = y + 1;} }
dis1 = (float)(((xt - x2)*(xt - x2)) + ((y - y2)*(y -y2)));
rad1 = gs_sqrt(dis1);
dis2 = (float)(((x - x2)*(x - x2)) + ((yt - y2)*(yt -y2)));
rad2 = gs_sqrt(dis2);
if(gs_abs(rad1 - rad) < gs_abs(rad2 - rad))
{x = xt;}
if(gs_abs(rad1 - rad) > gs_abs(rad2 - rad))
{y = yt;}
count++;
goto label;
}
}
```