Game Development Community

AI Functions

by Caleb · in Technical Issues · 06/19/2006 (1:05 pm) · 4 replies

When using starter.fps, I can call things like:

%this.setMoveDestination(LocalClientConnection.%obj.getTransform());

or

%this.setAimObject(%obj);

But in my custom game folder (not based off of starter.fps), I can't call these things because the functions don't exist. I would really like to know were these functions are so I can figure out how to modify or create new ones for my game.

I don't mind getting my hands dirty with code, I just need someone to tell me were to look.

Thanks.

#1
06/20/2006 (4:08 pm)
Well after looking over the source code I finly made It work. However I still have two more questions.

One:
How do I make him stop? I've tried setting the destination to NULL like the AimAt function but it doesn't work.

Two:
What wrong with this code? (aside from the schedule).

function Chase(%this)
{
   %this.setMoveDestination(myGuy.getPosition());
   schedule(1, 0, Chase);
}

I know that "BadGuy1.setMoveDestination(myGuy.getPosition());" works but "%this.setMoveDestination(myGuy.getPosition());" and then calling BadGuy1.Chase doesn't
#2
06/20/2006 (4:20 pm)
Well.... the code look's ok.

to get his to stop.. it's simple %obj.stop().
Quote:know that "BadGuy1.setMoveDestination(myGuy.getPosition());" works but "%this.setMoveDestination(myGuy.getPosition());" and then calling BadGuy1.Chase doesn't

Not quite sure i follow... but you won't be able to call badguy1.chase(), be cause your function chase is not a member of any class.... you'd have to do chase(badguy1)
#3
06/24/2006 (6:30 am)
OK, new question. I got the code below to work without "BadGuy::" and "%this" in the functions. But when I try it now nothing happens. it can't find %this.

$chasestat = 1;

//Get proximity to player
function BadGuy::AIProx(%this)
{
   if (VectorDist(myGuy.getPosition(), %this.getPosition()) < 51)
   {
      Chase();
   }
   else
   {
      StopChase();
      schedule(1, 0, AIProx);
   }

   $chasestat = 1;
}

//stop the chase
function BadGuy::StopChase()
{
  $chasestat = 0;
}

//Chase Player one
function BadGuy::Chase(%this)
{
   if (VectorDist(myGuy.getPosition(), %this.getPosition()) < 51)
   {
      %this.setMoveDestination(myGuy.getPosition());
      if ($chasestat $= 1)
      {
         schedule(1, 0, Chase);
      }
      else
      {
         $chasestat = 1;
         %this.stop();
      }
   }
   else
   {
      %this.Stop();
      AIProx();
   }
}

I thought that "%this" would be the object using these functions. Anyway its most likly somthing simple but I just haven't spent a lot of time on this, so some help would be nice.

Thanks.
#4
06/24/2006 (6:56 am)
I think this resource will help you:

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9615

I havn't looked into it much but I think it gives the AIplayer an object to move to. May be easier to work off.