On draw actor of an enemy I have this to get all the actors it's colliding with and to see if they're in the range, and then get the closest one.
- Code: Select all
int i, n, mindist = 1000;
Actor * cols = getAllActorsInCollision(range, &n);
Actor * closest = NULL;
for(i = 0; i < n; i ++)
{
if(cols[i].team == 1)
{
int d = distance(x, y, cols[i].x, cols[i].y);
if(d < mindist)
{
closest = (cols + i);
mindist = d;
}
if(closest)
{
target[cloneindex] = closest;
attack = 1;
}
else
{
target[cloneindex] = NULL;
attack = 0;
}
}
}
}
Then, on animation finish I have this:
- Code: Select all
int i;
if(attack)
{
attack = 0;
if(target[cloneindex] != NULL)
{
target[cloneindex]->hp -= 1;
}
But the target never loses hp. I made a debug string actor and it has
- Code: Select all
sprintf(text, "%s: %i", target[0]->clonename, orc.attack
And it correctly displays the clone name of the orcs target and it says it's attack is 1. Obviously I left out the script that does animations, but it all works fine. The orc faces the target, he will move toward the target, he will attack the target, the target just will not lose health. The animation scripts change no variables either.