Game Development Community

t2dPath and Node detecting

by Luis Rodrigues · in Torque Game Builder · 05/14/2011 (11:02 am) · 3 replies

Hi all

Am still new to TGB and am doing a small project to learn it and i need some help.

Here is the problem: I have a behavior attached to an AI that Attaches that AI to a path and makes it move around it in a loop - so far so good. But i need someway to make him stop for a few seconds on every node before moving on.

I there a way to get an event or something to the behavior of that AI everytime it reaches a Node, so i can give it a time or something like that to make it wait a couple of seconds?

Thanks in advance

About the author

Started Programming age 12 on 48kb ZX Spectrum than moved to Turbo Pascal, Turbo C++, Delphi, Java, etc. Currently Working as a programmer of in-house tools 4 a technical translations company, and working with WinterLeaf Entertainment on off days


#1
05/15/2011 (4:06 am)
So i figured out part of the problem - use onReachNodeEvent.

So i added this to the script:

function t2dPath::startAgain(%this, %object)
{
   %this.setSpeed(%this.getAttachedObject(%object), %speed); 
} 

function t2dPath::onReachNode(%this, %node, %object, %endNode) {    
    %this.setSpeed(%this.getAttachedObject(%object), 0);
    %this.schedule(2000, 'startAgain', %object);
}

only problem is, now the AI stops at the node but never moves again.
Ideas?

Thanks
#2
05/15/2011 (5:10 am)
so i made a few small changes - added lnode and mspeed as dinamic fields on the path and changed the code to:

function t2dPath::startAgain(%this, %object)
{
   %this.setSpeed(%this.getAttachedObject(%object), %this.mSpeed); 
   echo("schedule performed");
}

function t2dPath::onReachNode(%this, %node, %object, %endNode) {
    echo(%node);
    if ((%this.lNode == 0) || (%this.lNode != %node)) {
       %this.lNode = %node;
       %this.setSpeed(%this.getAttachedObject(%object), 0); 
       %this.schedule(2000, "startAgain", %object);
       echo("Schedule attempted");
    }
}

as you can see i added some echos for console output and this is what i got:

1605
Schedule attempted
schedule performed
1605
1605
1605
1605
1605
1605

from then on just keeps printing 1605 where i echo de node reached
I have 8 nodes on that path but apparently they all have the same ID reported to onReachNode.

as you can see it did stop at the first node found - but never again loop after loop.

ideas?
#3
05/15/2011 (5:49 am)
Finally got this solved

Had a really stupid error in the parameters for onReachNode and also had to make arrangements because when i started the AI moving again it would always reset to start node - so i change start and end nodes for that AI right after stopping it

here's how it's done now

function t2dPath::startAgain(%this, %object)
{
   %this.setSpeed(%object, %this.mSpeed);
}

function t2dPath::onReachNode(%this, %object, %node) {
    if (%this.lNode != %node) {
       %this.lNode = %node;
       %this.setSpeed(%object, 0); 
       %this.setStartNode(%object, %this.lNode);
       %this.setEndNode(%object, (%this.lNode + %this.getNodeCount() - 1) % %this.getNodeCount());
       %this.schedule(2000, "startAgain", %object);
    }
}

Anyone having a cleaner way to do this let me know please