Basics
Now im going to show how actual things working. My descriptions will be supported by images taken from example im about to show, as well as whole media, source code and binary included, so you can try yourself. So, lets get started.
After library is initialized, next step is to create both, search engine and navigation world, as you can see on pic bellow.
After that, if you compile your proggy, it will not be much visible..and you should be able to see image like this.
That looks nice, but we still cant see anything related to our pathfinding. So, just to warm up things a bit, lets create small functions called create_markers() and update_markers(), what will create and draw all available navigation nodes our search engine knows about. Details about each added function Ill not describe here as they are all included in source, so ill just say what they do. Now, our code at initial stage should look like this :
Now, if we run our proggy again, we should be able to see all searchable nodes exist, as its shown on pic below.
This is something B) . Now we see our all nodes we can search for best path. I want to notice that, this particular example is very nice example of very ugly setup for navigation mesh. Reason for that is unnecessary amount of search nodes as plenty of surfaces can be literally connected just with very few nodes actually, especially straight parts of level, without any obstacles. Basically this navigation grid has over 2000 nodes while whole thing can be done with very few (200-300 hundreds max). So, pay attention on way you create your navigation mesh. Now. lets do something more solid. Lets actually search some paths, shall we? In order to do that, Ill create few more functions, just to make things very easy to deal with. Additional functions are:
pick_start()
pick_end()
distance()
create_path_markers()
delete_path_markers()
Thats it. Functions are obviously, self explanatory, but ill still just make small note about their purpose.
pick_start() is function what will set up our search start position. Its done by moving mouse over level and hitting LEFT MOUSE BUTTON. After that, you will be able to see green color marker used to show start location.
pick_end() is function what will set up our search destination position. Its done by moving mouse over level and hitting RIGHT MOUSE BUTTON. After that, you will be able to see red color marker used to show destination location.
distance() is function what will return distance between two Vec3 . Simple as it is.
create_path_markers() function will create markers, but this time, markers assigned to our result path, so we can actually see how our path look like.
delete_path_markers() function will delete existing path markers before new path is calculated so we can see updated path.
So, after adding this, our code should look like this:
So far so good...so lets just test it. Lets determine further distance on this level (diagonal distance). Left mouse click at one diagonal corner, and then right click on opposite one. After that, just hit enter and violaaaa..our path is in fron of our eyes and it should look like this:
Niiiceee and fast.. Actual path search is done inside If-Then block i forgot to show, but its all inside source code so you can see yourself. Its very easy and simple. I hope you enjoyed this basics of AI. Next lesson is about steering basics. Stay tuned, and please, let me know if there is any particular area, you are actually interested to hear so i can make much better and useful lessons. Cya..
Download Linky and note:
You have to copy your Shaders folder in order to compile and run exe. Its compiled against 2.3x, but it should work with any version.
http://www.mediafire.com/?4nh4go346ecabmf
EDIT:
As i mentioned , current EXE provided, is compiled against 2.3x, and source code is from that version. Curtesy of Mac, here is updated version of source file, since one i have posted, clashing with newest versions of LE. Its not about AI library but Newton.DLL and way LE is initialized (doesnt work on new LE versions as it is on source i have provided).
Here is linky for new source file, thanks to Mac .
linky:
- 1
8 Comments
Recommended Comments