3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: [1]

Author Topic: an A* Pathfinding Demo  (Read 2855 times)

« on: September 12, 2009, 11:22:51 AM »
Ok, It's far from beeing optimized and there are french comments, but it works :)
To run it you have to put the "AStarDemoM" folder in your RigidBody/data/ folder.
This is just a sample application of A* but you can use it in many other ways.
I used "Nodes" for this path, but you can use whatever you want.

If anyone manage to do something else of it I would be glad to see the result.
And if anyone wants to make a path editor for it: be my guest ;)
Enjoy...

Edit: Updated the demo again to add "line of sight" for a better path refining and only launching A* when needed: "A_Star_Demo.3dr"
(You first need to install the previous "IF-AStarDemo.zip" to get the mesh to make it work, if you already have a previous version: no need to download it again :) )
« Last Edit: September 25, 2009, 04:05:37 AM by IronF »
« Reply #1 on: September 12, 2009, 11:35:53 AM »
Nice IronF, it works like a charm :)
Thanks.
« Reply #2 on: September 12, 2009, 06:11:29 PM »
I forgot a little something ::)
Just updating the "IF-AStarDemo.zip" version... (the uncompiled one)

If you have any questions, I'll try to help.
I'll make a path editor, but first I have to finish my AI system and make some final choices for my game. This can take some time :)
« Last Edit: September 12, 2009, 06:18:03 PM by IronF »
« Reply #3 on: September 14, 2009, 02:54:32 AM »
That is the biggest piece of code I have seen untill now on this forum  :o
Works like a charm  ;)
FPS game creator for 3drad and >2000 games GamesAtNight
« Reply #4 on: September 14, 2009, 08:38:31 AM »
Fantastic IronF, thanx for sharing  :)
« Reply #5 on: September 14, 2009, 11:58:52 AM »
Now, a tutorial for this piece of art, should be good. ;)
« Reply #6 on: September 14, 2009, 02:56:58 PM »
Ahhh
I was worried nobody asked...

To understand what A* does you can read this page:
http://www.policyalmanac.org/games/aStarTutorial.php

To use my sample you just need to fill a few arrays.
float[]PathFindx(7);
float[]PathFindy(7);
float[]PathFindz(7);
Those are the Vector3 coordonates of the "nodes".
Node0 is the first one, node1 the second one....

Then you need to tell what are the links between those nodes (Those links are call "Arc")
So you have to fill
int[]ArcStart={0,1,1,1,2,3,3,4,4,5,5,6};
 int[]ArcEnd={1,0,2,3,1,1,4,3,5,4,6,5};
Node0 is only linked to node1.
So you write 0 in ArcStart and 1 in ArcEnd.
Node1 is linked to 3 nodes: node0, node2 and node3
You have to create 3 ArcStart with node1.
...

Those "Arc" have a "cost" (the "G Cost")
float[]ArcCost
I used distance between nodes as "G Cost", you can use something else if you want or increase the cost of certain Arcs to avoid them.
The script is actualy autofilling this array with:

      ArcCost.resize(ArcStart.length());
      int n;
      for(n=0; n < ArcStart.length(); n++)
      {
         NodDistance(ArcStart[n],ArcEnd[n]);
         ArcCost[n]=Dist;
      }

 so if you want you can skip it

That's all you have to fill.

(dont forget to delete "Vector3 Node0;" to "Vector3 Node6;" at the top of the script and  "iObjectLocation(OBJ_220,Node0);" to " PathFindz[6] = Node6.z;" in the "if (iInitializing())"

Then if you want to call the script:
(It's in the main section)

      FindEndNod();
      FindStartNode();
Will find the nearest node of the "thing" you want to move (StartN) and the nearest node of the spot where you cliked (GoalN).
You dont have to use them if you want your "thing" to move from node to node...

PathSearch (StartN,GoalN);
Will launch the pathfinding.

P.S. I just wanted to thank you all for taking the time to answer my questions :)
« Last Edit: September 15, 2009, 04:11:37 AM by IronF »
« Reply #7 on: September 16, 2009, 09:17:10 PM »
Thank you. Now I can understand what the code is doing.
Pages: [1]