Hi,
How can I make my actor to move to the closest "tree" actor?
int n;
double mindist = 10000; //Initialize min distance with some high value
Actor *actors, *closest = NULL;
//Get all actors that collides with the sensor actor
actors = getAllActorsInCollision("Event Actor", &n);
if(actors)
{
int i;
for(i = 0; i < n; i++)
{
if(strcmp(actors[i].name, "player") != 0) //Ignore the player actor
{
double d = distance(player.x, player.y, actors[i].x, actors[i].y);
if(d < mindist)
{
//Hold the closest actor
closest = (actors + i);
mindist = d;
}
}
}
}
//Move the closest actor, if any
if(closest)
{
MoveTo(closest->clonename, 0, 0, 5, "player", "");
}
MoveTo(closest->clonename, 0, 0, 5, "player", "");
if(strcmp(actors[i].name, "player") != 0) //Ignore the player actor
if(strcmp(actors[i].name, "tree") == 0) //On tree actors
Users browsing this forum: No registered users and 1 guest