Game Development Community

Getting Player to follow new path

by Nmuta Jones · in Torque Game Engine · 10/29/2008 (2:43 pm) · 2 replies

www.mediabreeze.com/paths.jpg

I have created a new set of paths, using G.Notman's pathfinding resource.

I implemented it in AFX 1.1, and I am having trouble getting my newly created bot to follow it.

In the past, I would use:
%player.followPath("MissionGroup/Paths/Path1",-1);


but now I am trying
%player.followPath("MissionGroup/Paths/AIPaths",-1);


and it's not working, the bot stands still.

Any help would be appreciated.

#1
10/29/2008 (3:39 pm)
Be glad to help :) Can you post the code for the function followPath()?

Also, post the part of your .MIS (mission) file where AIPaths is defined please.
#2
10/29/2008 (3:54 pm)
Ok thanks:
function AIPlayer::followPath(%this,%path,%node)
{

	//G.Notman Begin
   if (isObject(AiPaths))
   {
      %this.stopThread(0);
      %this.SetOnPath();
      return;
   }
   //G.Notman End

   // Start the player following a path
   %this.stopThread(0);
   if (!isObject(%path)) {
      %this.path = "";
      return;
   }
   if (%node > %path.getCount() - 1)
      %this.targetNode = %path.getCount() - 1;
   else
      %this.targetNode = %node;
   if (%this.path $= %path)
      %this.moveToNode(%this.currentNode);
   else {
      %this.path = %path;
      %this.moveToNode(0);
   }
}

AND

this is the SetOnPath code. IT WORKS in a Fresh install of 1.5.2
This is a fresh install of AFX , so there are some differences in the AI Manager.

The code below includes some of G.Notman's pathfinding method combined with my own method (getClosestNode() ) of finding which node in the path is closest to the closest "human" player.


function AIPlayer::SetOnPath(%this)
{
   //%tgt=AiPaths.getObject(getRandom(0, AiPaths.getCount()-1));
   %tgt=AiPaths.getObject(AIPlayer::getClosestNode(%this));
   
   
   messageAll("",'Kork is looking to move to node: %1', %tgt.getID());
   
	//This empties the bots current path
	%this.patharray.empty();
	
   %path=AiPaths.findpath(%this.getposition(), %tgt.getposition(), $AiPaths::Method, $AiPaths::Random);
   
	if(%path == -1)
   {
      echo(%this.getposition());
      echo(%tgt.getposition());
	 	%this.patharray.add(%this.getposition(),0);
	 	
	 	%this.endNode=0;
	   %this.curNode=0;
	   %this.moveToNode(%this.curNode);
	   
	 	return;
   }
   
	%count=getWordCount(%path);
	for (%i=0; %i<%count; %i++)
	{
	   %this.patharray.add(getWord(%path, %i).getposition(), %i);
	}
	%this.patharray.add(%tgt.getposition(), %count);
	
	%this.endNode=%count;
	%this.curNode=0;
	%this.moveToNode(%this.curNode);
}

and here is the relevant part of my mission code (at least the start of the paths part):

new AIPathGroup(AiPaths) {
      canSaveDynamicFields = "1";

      new AIPathNode() {
         canSaveDynamicFields = "1";
         position = "430 310 219.516";
         rotation = "1 0 0 0";
         scale = "1 1 1";
         dataBlock = "PathNode";
      };
      new AIPathNode() {
         canSaveDynamicFields = "1";
         position = "422.792 310.295 219.517";
         rotation = "1 0 0 0";
         scale = "1 1 1";
         dataBlock = "PathNode";
      };
      new AIPathNode() {
         canSaveDynamicFields = "1";
         position = "414.836 310.62 219.517";
         rotation = "1 0 0 0";
         scale = "1 1 1";
         dataBlock = "PathNode";

etc....................

Traditional Paths in Torque look like this in my mission:

new SimGroup(paths) {
      canSaveDynamicFields = "1";

      new Path(Path1) {
         canSaveDynamicFields = "1";
         isLooping = "1";

         new Marker(Path_Mark) {
            canSaveDynamicFields = "1";
            position = "420 300 221.011";
            rotation = "1 0 0 0";
            scale = "1 1 1";
            seqNum = "1";
            type = "Normal";
            msToNext = "100";
            smoothingType = "Spline";
         };
         new Marker() {
            canSaveDynamicFields = "1";
            position = "447.831 207.249 211.417";
            rotation = "1 0 0 0";
            scale = "1 1 1";
            seqNum = "2";
            type = "Normal";
            msToNext = "100";
            smoothingType = "Spline";


etc............