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.
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.
About the author
#2
04/24/2010 (3:27 am)
Yes, the marker seqNums are indexed just as you say.
#3
And the title of this thread says...
And when you ask
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:By manually you mean? console?
When manually controlling an AI around a path how do you keep the smooth flow from last node to first?
#4
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.
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
Add this function in your aiPlayer.cs:
And replace your DemoPlayer::onReachDestination with this:
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!
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
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.
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
That thread was addressing a modification of AIPlayer.cs. This thread is a vanilla project with no modifications except testing yours above today.
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.
Torque 3D Owner Marcus L