First attempt at pathfinding

posted in GiTS' Journal
Published October 09, 2014
Advertisement
So really it's about time I started working on some core mechanics and being able to play test things to see if they're actually fun, and AI is quite a big part of that. I understand some principals of pathfinding but never actually attempted it so this was a pretty interesting (and enjoyable) exercise for me. For this I needed a new playground to be able to really test the system I was about to put in place... so here it is!

[sharedmedia=gallery:images:5710]
It has some walls, some areas without floor tiles and some stairs etc, this is enough for now for the basic set-up methinks! So firstly I need some nodes and there's several ways I can do this:

  • The floor tile prefab has nodes as children
  • Generate the nodes automatically
  • Do it manually (ALL OF THE NOPE!)

Having the floor tiles as the parent of nodes would be convenient but several things would still need to happen, such as linking nodes to their neighbours. Doing this manually would just take too long and would be prone to errors, I could write a tool but then why not just generate the nodes with that as well? Generating the nodes would be quick and easy, I can link them all up and get consistent results across all maps and levels. I could make it customisable as well with settings to make it any size I want.

So the end result is this! Each square represents a node to be used in pathfinding and it's 2x2 nodes per "floor tile". Maybe I should have mentioned it earlier but I am using A*, but I am continuously doing research and reading up on the subject and I'm finding out new things all the time so there may be a combination of systems in the end product. Influence mapping is something I really want to implement as part of it because the game would benefit greatly from it the longer it goes on ;D
[sharedmedia=gallery:images:5711]

This is 5x5 nodes per floor tile, which so far is the amount I am leaning towards for the majority of the maps. I can choose the amount of nodes I want per floor tile (the density) when I generate them, so that is awfully convenient.
[sharedmedia=gallery:images:5712]

I eventually ran into the problem of what to do between the layers of the level and how to have the AI traverse it. I did experiment with a combination of the earlier mentioned techniques, one being having the stairs prefab with nodes as its children and hooking it up manually to neighbouring nodes, but that would grow tedious even with the smaller amount of nodes to deal with.
So I didn't go for that either, it's just best if I automate it as much as I can, so what did I do? Using each stair object in the scene, I took the origin of the stairs and which direction going up they were to start off, from here I know where the nodes should be that intersect with the bottom and top of the stairs due to everything being in a fixed position. I locate the first node that is "highest" on the y-axis and work my way down using it's stored southern neighbour to get the rest at the top and bottom of the stairs. It's then a simple case of just neighbouring those nodes together to pair the top and bottom layers of the map via the stairs and also enabling them for pathfinding.

And that's it! It works really well and the AI happily goes up the stairs to reach a given destination. The only thing I need to do now is have some reminder to tell myself to regenerate the nodes if the levels geometry is changed, because that has given some interesting results when the AI has used old data xD
[sharedmedia=gallery:images:5713]

It may or may not be the most elegant system (or even how you are supposed to do it xD), but it works really well and gives fast results that I am (so far) happy with smile.png


And to finish off here is a little extra something, I like to test out ideas for maps or locations and wondered what it'd be like to walk over some traffic that gives some life to the city. Think of it like, concepting some locations in the game.
(Hopefully youtube works at time of publish?)


~ GiTS
2 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement