That blog does not exist

Game Development Community

Basic A* implementation in Torque2D

by John Vanderbeck · 04/17/2005 (7:33 pm) · 6 comments

Download Code File

This resource shows a very basic implementation of the A* pathfinding algorithm in Torque2D.

A couple notes here:

1) This can defintly be improved.
2) This is the first time i've ever done A* so suggestions are welcome.
3) This isn't so much a tutorial but the code is commented. A basic level of programming, TorqueScript, and Torque2D knowledge is expected to get the most out of this.

How to use it:
You'll need your own T2D exe, but its stock. I'm assuming you know how to set this up its not hard. This is all script side.

Run the application, left click once to select the start node, left click a 2nd time to select the goal node, then left click a 3rd time to select the tile type which is UNPASSABLE. After the 3rd click the path will be determined. Tiles will be highlighted to show what happened. The brighter tiles are tiles searched. The highlighted but not as bright tiles are the actual path it found.

Please be kind to it. There is very little error checking beyond the basics. I have no idea what will happen if you try to make it search for an impossible path beyond that it won't lock up.

#1
06/05/2005 (7:01 pm)
FYI: This isn't running for me. Am getting a the following error: "T2D.exe has encountered a problem and needs to close. We are sorry for the inconvenience."

-Unk
#2
08/04/2005 (1:46 pm)
Hmm.. There seems to be some bug - quite often when I try to find path from ie (0,0) to (2,0) I get path far from being shortest - it walks around instead of going straight down... Weird.

cheers,
Arkadesh
#3
08/07/2005 (12:54 pm)
I've found the problem - if anyone wants to find shortest paths find

function estimateCost(%node, %goalNode)

and change %h calculation method to:

%h = mSqrt((%goalNode.gridX - %node.gridX)*(%goalNode.gridX - %node.gridX) + (%goalNode.gridY - %node.gridY)*(%goalNode.gridY - %node.gridY));

cheers,
Arkadesh
#4
08/18/2005 (8:39 am)
I'm having the same problem as Unk. It always give me an error and won't start. :(
#5
09/25/2005 (11:18 pm)
Can you tell me whether is Arkadiusz's revision valid ?
And how to run the demo, thanks a lot .

--HugeOne
#6
10/29/2005 (3:42 pm)
One this to note, be sure to clear each node's parent when you are walking thru the path otherwise it can cause lockups