Public Group

# Pathfinding in a tower defense game.

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

## 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 on other sites
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 on other sites
Braindigitalis++;

Good thinking, cheers for that =)

I'll let you know if I get it working!

Ollie.

##### Share on other sites
Heyy, got it working! I'm a happy man =D

Here it is! Each circle represents a node.

Cheers for the help.

Ollie.

##### 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 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!

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634090
• Total Posts
3015434
×