Jump to content
  • Advertisement
Sign in to follow this  
ollyb342

Pathfinding in a tower defense game.

This topic is 2742 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys,

I've been making a 3D tower defense game with OpenGL and LWJGL (Java) and I'm at the point where I'd like to start thinking about enemies etc.

Now, I've been following this tutorial so far to learn A* pathfinding, and I'm understanding the theory well. However I'm now at a stage where I need to somehow get my 2D integer array of tile types into a load nodes with connected neighbouring nodes and I have no idea at all how to progress.

So GD.net gurus, any ideas on how I should progress?

For those that are interested, the game is currently at this stage: Lolliver Defense
Cheers!

Ollie.

Share this post


Link to post
Share on other sites
Advertisement
Your two dimensional tile array is basically your nodes. Nodes is just the fancy mathematical term for the same thing, so if you allocate a set of arrays with the same dimensions as your tile map, you can use these to store the correct F, G and H values. In my own implementation last time i implemented A* i also used a list of coordinates which i then reversed upon finding the correct route, as part of findind a route is tracing a path back from where you ended up to where you start using the values in your nodes.

I can provide source code for this in C++, drop me a line if you would find that useful!

Share this post


Link to post
Share on other sites
For the most part (there are exceptions) tower defense games have the easiest pathfinding of any game and people over think it.

Your game might be different but I am going to guess that it is not. For your monsters, they can pretty much only go in one path. Point A always leads to B, which leads to C and so on. So the reality is there is no pathfinding, it is just a array of tiles that list where they can go and in what direction. Anything else is just a lot of processing for no real reason.

Share this post


Link to post
Share on other sites
You're correct about the necessary AI being quite simple for a tower defense game.

But apart from some dodgy handmade AI I made for a pacman game I'm not that well experienced, so this was a nice introduction to more widely recognised pathfinding algorithms.

After implementing in Java now I'd definitely use it in other projects, it's amazing!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!