Page 1 of 1

get clone object number from `movetoclosestactor` routine

PostPosted: Thu Jun 14, 2007 7:10 pm
by akhad
I've found the movetoclosestactor code very handy (code follows) but I'd like to get the closest clones object number too. How can I extract the actual number of (closest->clonename) ready for display in a text.number ?

movetoclosestactor code:

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", "");
}

PostPosted: Thu Jun 14, 2007 9:13 pm
by makslane
You can use:

Code: Select all
textNumber = closest->cloneindex;

PostPosted: Thu Jun 14, 2007 9:36 pm
by akhad
Yes, that makes sense now I see it. I've only just really started looking into clone actors and the power is impressive. I'd really like to see more tutorials on this, it's the key to potentially very professional game structures.
Thanks.