Updates AIPlayer script class to account for looping paths and slows the aiplayer down on the lastnode if it's not a looping path.

This commit is contained in:
cpusci 2013-08-05 09:28:58 -05:00
parent 3e3006024c
commit 140892e032

View file

@ -140,26 +140,31 @@ function AIPlayer::followPath(%this,%path,%node)
function AIPlayer::moveToNextNode(%this) function AIPlayer::moveToNextNode(%this)
{ {
if (%this.targetNode < 0 || %this.currentNode < %this.targetNode) %pathNodeCount=%this.path.getCount();
{ %slowdown=0;
if (%this.currentNode < %this.path.getCount() - 1)
%this.moveToNode(%this.currentNode + 1); %targetNode=%this.currentNode + 1;
else
%this.moveToNode(0); if (%this.path.isLooping) {
%targetNode %= %pathNodeCount;
} else {
if (%targetNode >= %pathNodeCount-1) {
%targetNode=%pathNodeCount-1;
if (%currentNode < %targetNode)
%slowdown=1;
}
} }
else
if (%this.currentNode == 0) %this.moveToNode(%targetNode, %slowdown);
%this.moveToNode(%this.path.getCount() - 1);
else
%this.moveToNode(%this.currentNode - 1);
} }
function AIPlayer::moveToNode(%this,%index) function AIPlayer::moveToNode(%this,%index,%slowdown)
{ {
// Move to the given path node index // Move to the given path node index
%this.currentNode = %index; %this.currentNode = %index;
%node = %this.path.getObject(%index); %node = %this.path.getObject(%index);
%this.setMoveDestination(%node.getTransform()); %this.setMoveDestination(%node.getTransform(),%slowdown);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------