Game Development Community

AIPlayer FollowPath Loop At End

by Benster · in Torque 3D Professional · 04/23/2010 (7:40 pm) · 7 replies

Using the standard aiPlayer.cs with AIManager enabled in gameCore.cs I have a 23 node path with looping enabled. A single AI uses this path and I control him via followPath. However, the AI will not take the shortest path from node 23 to 0 (even though they are right next to each other).

When manually controlling an AI around a path how do you keep the smooth flow from last node to first?

FYI: same results in Beta 5 and 1.1 Beta 1.

#1
04/24/2010 (2:47 am)
Have you checked that your markers seqNum are correct? To set up a proper path you'll have to index your markers from 1(first node) to X(last node). Not sure if this is your problem tho.
#2
04/24/2010 (3:27 am)
Yes, the marker seqNums are indexed just as you say.
#3
04/24/2010 (4:03 am)
When you say...
Quote:However, the AI will not take the shortest path from node 23 to 0 (even though they are right next to each other).
... You know that the AIPlayer doesn't look for the closest marker, it only follow the marker as they are indexed (also know that there are resources out there that adds an AI which searches for the closest markers, do a search).

And the title of this thread says...
Quote:AIPlayer FollowPath Loop At End
... If you want to make you AI go the same way back after looping, you'll have to make 23 new markers going the same way.

And when you ask
Quote:
When manually controlling an AI around a path how do you keep the smooth flow from last node to first?
By manually you mean? console?
#4
04/24/2010 (4:27 am)
Yes, I want the AIPlayer to follow the markers as they are indexed and when reaching the end of the path go to the first. I do not want the AIPlayer to turn and go backwards.

For example, the NPC is on node 20 and receives the command (via script) to go 5 nodes it should move to 21, 22, 23, 0, and stop at 1.

I hope that helps clarify what I'm asking. Thanks for the responses Marcus.
#5
04/24/2010 (5:36 am)
Here, i made your code:

Add this function in your aiPlayer.cs:
function AIPlayer::moveForward(%this, %toMove)
{
   %this.toMove = %toMove - 1;
   %this.moveToNextNode();
}

And replace your DemoPlayer::onReachDestination with this:
function DemoPlayer::onReachDestination(%this,%obj)
{
   // Moves to the next node on the path.
   // Override for all player.  Normally we'd override this for only
   // a specific player datablock or class of players.

   if(isDefined("%obj.toMove"))
   {
      %obj.toMove -= 1;
      
      if(%obj.toMove >= 0)
         %obj.moveToNextNode();
   }else{
      if (%obj.path !$= "")
      {
         if (%obj.currentNode == %obj.targetNode)
            %this.onEndOfPath(%obj,%obj.path);
         else
            %obj.moveToNextNode();
      }
   }
}

Now spawn an aiPlayer, and call bot.moveForward(index);, where "bot" is the id or name of your aiplayer, and index is the number of markers the ai should move forward.
Note: The only "issue" you might experience with this code is that the aiPlayer will slow down when moving to the first node.

Hope it works for you!
#6
04/25/2010 (3:10 am)
Reading your post on this thread, it seems that there is something wrong in your aiPlayer code or in the path. Have you modified your aiPlayer code, because the standard code is supposed to loop when reaching the end of the path. Have you tried going in an empty map, making 4 markers, putting them in an path, calling the path something like "path", entering AIPlayer::spawnOnPath(name,"MissionGroup/path"); in the console, then get the aiPlayers id, then write botid.followPath("MissionGroup/path",-1);.

I think its more likely that you didn't put -1 in your followPath function. As for the code i made above, what it does (if you need it), is that your aiPlayer will walk as many nodes as you tell him to and then he'll stop.
#7
04/25/2010 (8:09 am)
The -1 option is a blind running of every node and does loop correctly back to 0 at the end of the path. However, as long as -1 is passed there is no interaction or control of how many nodes the AI moves, it just continuously laps the path.

That thread was addressing a modification of AIPlayer.cs. This thread is a vanilla project with no modifications except testing yours above today.