Jump to content
  • entries
    2
  • comments
    8
  • views
    3,533

Basics


Naughty Alien

2,960 views

 Share

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.

 

image.jpg

 

After that, if you compile your proggy, it will not be much visible..and you should be able to see image like this.

 

image.jpg

 

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 :

 

image.jpg

 

Now, if we run our proggy again, we should be able to see all searchable nodes exist, as its shown on pic below.

 

image.jpg

 

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:

 

image.jpg

 

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:

 

image.jpg

 

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.. :D

 

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:

http://www.mediafire.com/?o1nvgh6nao866vr

  • Upvote 1
 Share

8 Comments


Recommended Comments

..thanks YouGroove .. it will help to hear actually what people would like to have as tutorials, rather than me mocking around by guessing what would be good to have.. :)

Link to comment

I never get these things.

 

For that type of terrain/level, I would just use collision avoidance as the bulk of the terrain is traversable - therefore the AI simply needs to go left or right around something like a tree - ie there's nothing to pathfind.

Link to comment

..mm..while that may be correct, such approach will never return shortest path, and it will be rather difficult to control alternate routes, in case you have many characters and path you loking for by trying to go left-right is simply..stuck..also, this will work in any shape/complexity of level, and I decided to go with this sort of level for tutorials because its easier to follow, but it will work just same no matter how complex is level.. anyway, you will see in next tutorial where some form of labyrinth is involved and elevated path surface. :)

Link to comment

Ok, just starting to think about pathfinding in my game. How would what you are doing change with an .sbx file scattered with .gmf instead of a single .gmf?

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...