Node Pathfinding

Hey. So here’s an example of path-finding using nodes, but rather than just positions stored in an array, they are actual objects in the scene. This means that it’s quite easy to have a path point to objects, even objects that move because you can simply parent a node to the object that you want to go towards. The script is complex, but you can simply change some variables to get the desired behavior (turn around on path completion, etc.), and the script only runs in the follower, meaning that the nodes are simple ‘filler’ objects (they perform no functions other than occupy a position in space and specify a position in the path). Also, since the paths are stored in the ‘pathnode’ variable in the object, you can even exchange paths between objects (for example, have one guard go to another and then that guard will take the first guard’s path). You recalculate the path using the RecalculatePath function, but since the path uses objects, you shouldn’t have to use that.

Note that you can turn around mid-path by changing the object’s ‘pathdir’ variable (1 is forward, -1 is back). However, turning around will only work once the object is on a node. I also made a TurnAround function that will make the object turn around on the path immediately. In order to implement this, you’ll have to copy the function to the object to call it, or you’ll have to put the updating portion of the script into a function and import the script as a module to execute the update function. The way I have it in the file is just that all objects run the script. So… That’s it. Here’s the file (it should work in 2.49, but it was made for 2.5). It also includes a normal map noise image that you can use for free in your projects, commercial and otherwise! Yeah, it’s cruddy, but hey, it’s free.

That is really nice!

Yes, very nice and very great!
The script is really complex (at least to me) but its cleanly written and all commented!
Thank you for sharing!

Thanks. It shouldn’t be too hard to use; I forgot to mention in the script that you can change the “obj[‘pathcompletion’]” to affect what the follower object does on completing the path.

0 = stop
1 = return to beginning
2 = turn around (reverse direction)
3 = snap to beginning

off of the top of my head.

I Really Like Stuffs like this.
Thanks For Sharing.

No problem.

Wow!! That is so cool. Finally an AI system that actually works on 2.5!! Thanks!!!

Okay I’m not understanding ‘tol’. What does it do? And why does it have values like 0.1 and 1.0 assigned to it in the parameters?

@Asif - It’s not really AI, just path-following. The ‘tol’ variable controls the tolerance used by the Close and PosClose functions. The less the value, the more precise the positioning has to be to be a match. For example,

Close(0.5, 0.4, 0.1)

would return 1, but

Close(0.5, 0.3, 0.1)

would not, as the absolute value of 0.5-0.3 is 0.2, not within the tolerance range.

I’ve learnt a lot from your blend file, thanks!!! But it took me all night since the script was a bit complicated…Could you make another more simple file, where there’s just one path and the script just outlines the very basic of node-path finding? I think that would help out noobs more. I still don’t have a clue what the functions Close() and Posclose() are for, if there was a single path then would those functions be necessary?

Btw I appreciate and am very grateful for all the help you’re giving me. :slight_smile: