getallactors in collsion used for closest help

Talk about making games.

getallactors in collsion used for closest help

Postby jimmynewguy » Fri Apr 24, 2009 1:08 am

so i have a code in an actor that has a parent actor. And i want the parent actor to move twords the closest actor, and face it
Code: Select all
int n;
double mindist = 10000;
Actor *actors, *closest = NULL;
actors = getAllActorsInCollision("Event Actor", &n);


if(actors)
{
  int i;
  for(i = 0; i < n; i++)
  {
    if(strcmp(actors[i].name, "theActor") == 0)
 
    {
       double d = distance(parent.x, parent.y, actors[i].x, actors[i].y);
       if(d < mindist)
       {
           closest = (actors + i);
           mindist = d;
           angle = direction(parent.x, parent.y, actors[i].x, actors[i].y);
if(angle < 45 || angle > 315)ChangeAnimation("Parent Actor", "walkEast", FORWARD);
if(angle > 45&&angle < 135)ChangeAnimation("Parent Actor", "walkNorth", FORWARD);
if(angle > 135&&angle < 225)ChangeAnimation("Parent Actor", "walkWest", FORWARD);
if(angle > 225&&angle < 315)ChangeAnimation("Parent Actor", "walkSouth", FORWARD);
CreateTimer("Event Actor", "search", 1000);
       }
    }
  }
}
if(closest)
{
MoveTo("Parent Actor", 0.000000, 0.000000, 2.000000, closest->clonename, "");
}

this works great, however i would like it to also move to another actor type based of closest and not just theActor. i tried using or "||" and an else if with the same code but different name than theActor, but it won't work.
ps: i found the base of this code in a demo Mak made lol so it's kinda advanced (i just modified it):)

EDIT: ya so it turns out it does work.....i just put an extra ( and it was messing up the code) :roll: false alarm oh well, anyone need this closest code??lol
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron