Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (741)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (823)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Tower Defense pathfinding?  (Read 2330 times)
0 Members and 1 Guest are viewing this topic.
Offline Bassex96

Senior Devvie


Medals: 5



« Posted 2014-11-23 19:57:37 »

Hey guys, i'm working on a small tower defense game using LibGDX. I'm probably going to put an android port on the play store.

So, the game is coming along pretty nicely so far. I'm just trying to figure out the best pathfinding method...I was thinking of using A* but I think that may be a little much for what I need...

I started the project using a multidimensional array for the map, but i'm now thinking of switching to using tiled so it is easier to manage larger maps..I don't know if there is another way to do it using tiled, I do know I was having trouble using the A* method with tiled...

Basically, the enemies will follow a path from A to B...I could define waypoints, but it seems like there could be an issue with enemies running into each other, etc.

Any suggestions or tips?
Offline ThePixelPony

Senior Newbie


Medals: 3
Exp: 3 years



« Reply #1 - Posted 2014-11-23 20:33:26 »

They literally have paths drawn out in files as waypoints.

#BlameMicrosoft
Offline Bassex96

Senior Devvie


Medals: 5



« Reply #2 - Posted 2014-11-23 20:47:18 »

What do you mean? Who does?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CopyableCougar4
« Reply #3 - Posted 2014-11-23 20:49:01 »

@Bassex96

My suggestion would be to do this every frame:

1  
2  
3  
check if entities are blocking your path
determine a waypoint to target. if this has changed, re-pathfind
start moving


CopyableCougar4

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline Bassex96

Senior Devvie


Medals: 5



« Reply #4 - Posted 2014-11-23 21:00:12 »

That's what I'm going for. Just trying to figure out the best way to calculate the pathfinding..there aren't many obstacles and it's just from A to B, so I feel like a* might be too much..

This is the first time I've ever done any type of pathfinding.
Offline Gibbo3771

JGO Kernel


Medals: 128
Projects: 5
Exp: 1 year


Currently inactive on forums :(


« Reply #5 - Posted 2014-11-23 21:04:50 »

Try reading this

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline CopyableCougar4
« Reply #6 - Posted 2014-11-23 21:05:11 »

I think A* would be the best option, for your problem, as it is a grid-based and A* is good with determining the next step.

CopyableCougar4

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline Bassex96

Senior Devvie


Medals: 5



« Reply #7 - Posted 2014-11-23 21:48:26 »

That is awesome! Thank you Gibbo. A simple search probably would have found that for me! I didn't think about searching for tower defense specifics.

I agree, CC. I just needed some reassurance!

I just hope I can stick with this without getting bored. I'm only developing it for the experience, but I need to finish something completely so I can move forward to the games I have been planning for months.
Offline Gibbo3771

JGO Kernel


Medals: 128
Projects: 5
Exp: 1 year


Currently inactive on forums :(


« Reply #8 - Posted 2014-11-23 22:04:18 »

That website has way more than just that one article, have a look at the intro to a*. It is a good read.

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline Bassex96

Senior Devvie


Medals: 5



« Reply #9 - Posted 2014-11-23 22:32:12 »

Yeah, there is some good stuff on there! Thanks.

I'm rewriting this now to use tiled instead..It's too hard to manage in the array...My question is, how do I set up a grid to use a* with tiled? I tried this before and was unsuccessful. That's part of the reason, I decided to do it from scratch as I would already have a grid..I know it's something simple, but I don't see it.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Rayvolution

« JGO Spiffy Duke »


Medals: 379
Projects: 2
Exp: 2 years


Resident Crazyman


« Reply #10 - Posted 2014-11-24 03:35:30 »

Try reading this

Whoa, very nice link. This method is almost identical to the method I use in Retro-Pixel Castles. Very nice to have a visualizeable reference next time someone asks me how my pathfinding works. Cheesy

- Raymond "Rayvolution" Doerr.
Retro-Pixel Castles - Now on Steam!
LIVE-STREAMING DEVELOPMENT: http://www.hitbox.tv/rayvolution
Offline Gibbo3771

JGO Kernel


Medals: 128
Projects: 5
Exp: 1 year


Currently inactive on forums :(


« Reply #11 - Posted 2014-11-24 08:35:45 »

Yeah, there is some good stuff on there! Thanks.

I'm rewriting this now to use tiled instead..It's too hard to manage in the array...My question is, how do I set up a grid to use a* with tiled? I tried this before and was unsuccessful. That's part of the reason, I decided to do it from scratch as I would already have a grid..I know it's something simple, but I don't see it.

Represent both the map and your graph as a 2D array, use the center of the tile as the origin for positioning.

Simple have each tile represent a node in the graph.

So for instance, you have a wall tile at x = 4 and y = 6. This can be a blocked mode that is not valid for visiting.

The way I do it is create a 2D tile array and a 2D boolean array, as you iterate to generate your map, also grab the tiles block field and fire that it in the 2D boolean array.

All done, now pass it to your node map and use it to generate nodes.

This is the quick way, in reality every have needs custom path finding if you want to add things like weighted edges, move values etc.

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Pages: [1]
  ignore  |  Print  
 
 

 
xxMrPHDxx (21 views)
2017-11-21 16:21:00

xxMrPHDxx (14 views)
2017-11-21 16:14:31

xxMrPHDxx (16 views)
2017-11-21 16:10:57

Ecumene (114 views)
2017-09-30 02:57:34

theagentd (150 views)
2017-09-26 18:23:31

cybrmynd (258 views)
2017-08-02 12:28:51

cybrmynd (249 views)
2017-08-02 12:19:43

cybrmynd (247 views)
2017-08-02 12:18:09

Sralse (260 views)
2017-07-25 17:13:48

Archive (878 views)
2017-04-27 17:45:51
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!