🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How to transverse a road in a defend the tower game

Started by
6 comments, last by RamblingBaba 4 years, 6 months ago

Hello,

So I bought a really cool sprite collection of a Defend The Tower theme. They have some static background of curvy roads and sprites for enemies (look good!).

So I'm wondering what is the best way to have them follow the road? I thought about doing A* (which I can do) and putting collsion tiles around the road, but I don't think that will work correctly, because it doesn't line up as tiles. I suppose I could put pretend 8x8 tiles or something. Would looking into graphing be the most efficient way?

What is the best way to do this? Any articles or source codes would be much appreciated.

Thanks!

PS: Example of one of the maps.

https://ibb.co/BZCgNVs

Advertisement

Did the graphics come with any metadata that could be used for this? It seems like a graphics pack of this sort would include such metadata, as otherwise it could be difficult to use effectively.

What do you mean by 'graphing' and 'pretend 8x8 tiles' exactly? Maybe it's clear from context what you mean, but some clarification might help.

Just based on the image, it looks like the paths might be comprised only of axis-aligned line segments and quarter circles. If you don't have any metadata available, you could probably create such data yourself by identifying node positions and constructing paths manually and/or procedurally.

Zakwayda said:
Did the graphics come with any metadata that could be used for this? It seems like a graphics pack of this sort would include such metadata, as otherwise it could be difficult to use effectively.

What do you mean by 'graphing' and 'pretend 8x8 tiles' exactly? Maybe it's clear from context what you mean, but some clarification might help.

Just based on the image, it looks like the paths might be comprised only of axis-aligned line segments and quarter circles. If you don't have any metadata available, you could probably create such data yourself by identifying node positions and constructing paths manually and/or procedurally.

Hello,

I don't see any metadata for it. It looks like they have Unity stuff in it, which probably has something (AI folder). I'm doing this in C++ using SFML. What I mean by graphing is creating zones where they follow the nodes laid out along the path and make the node the width and height of the road. I can''t recall off the top of my head what that concept is called, but I briefly was reading about it back when I was learning A*. It was some type of zoning behavior.

What I mean by "pretend 8x8 (or whatever size)" is setting it up with tile data behind it (for this example 8x8) and setting the tiles around the border of the road "solid" and create a zone so the A* only reads within the road. The reason I said 8x8, is I assumed it would be easier to have smaller tiles to be able to get closer to the roads (since they curve).

I could manually put "directions" in, but not all the maps have the same pattern and the maps all come with single image objects to create your own if you wish too. It looks like they have some Tiled examples, which I briefly looked at and that's what gave me the idea of putting collision tiles around the road.

EDIT: I just made a fast example, but hopefully this gives a better idea. The red would be tiles (nodes, whatever the best size is), which would zone off and keep the pathfinding to the road. The enemies spawn on the green, A* is performed, and it goes to the orange circle where it decides to go left or right and continues A*. Ignore the fact that these are obviously random sizes and visualize them all the same.

PS: I realized I accidentally made a collision box green, that would be red as well haha. Thanks

Collision boxes and A* seems like overkill. Why not have fixed directions (the yellow line in your example) that the units follow? You can have one path for every different image/level, and the units can follow it like they are on rails.

1024 said:

Collision boxes and A* seems like overkill. Why not have fixed directions (the yellow line in your example) that the units follow? You can have one path for every different image/level, and the units can follow it like they are on rails.

I think that this is the best solution here since enemies have limited amount of paths to use and always have a solid target to reach to the player's base.

The way I would do it is to create some sort of spline and let enemies follow it with some random offsets. If there are multiple paths, then it's possible to create multiple splines and attach specific groups enemies to each path, that way for example fast units on crossroad can turn right and slow units can turn left.

I think that using pathfinding is over the top, since all your paths are already found - that's your roads.


G-Dot said:
1024 said:

Collision boxes and A* seems like overkill. Why not have fixed directions (the yellow line in your example) that the units follow? You can have one path for every different image/level, and the units can follow it like they are on rails.

I think that this is the best solution here since enemies have limited amount of paths to use and always have a solid target to reach to the player's base.

The way I would do it is to create some sort of spline and let enemies follow it with some random offsets. If there are multiple paths, then it's possible to create multiple splines and attach specific groups enemies to each path, that way for example fast units on crossroad can turn right and slow units can turn left.

I think that using pathfinding is over the top, since all your paths are already found - that's your roads.


I agree, I thought path-finding was too over the top. I thought there would be a more traditional solution. I actually really like your spline idea. That is something I can do, although I'll need to look into splines again. I think that's what I'll do.

Thanks for the help!

G-Dot said:
1024 said:

Collision boxes and A* seems like overkill. Why not have fixed directions (the yellow line in your example) that the units follow? You can have one path for every different image/level, and the units can follow it like they are on rails.

I think that this is the best solution here since enemies have limited amount of paths to use and always have a solid target to reach to the player's base.

The way I would do it is to create some sort of spline and let enemies follow it with some random offsets. If there are multiple paths, then it's possible to create multiple splines and attach specific groups enemies to each path, that way for example fast units on crossroad can turn right and slow units can turn left.

I think that using pathfinding is over the top, since all your paths are already found - that's your roads.


I agree, I thought path-finding was too over the top. I thought there would be a more traditional solution. I actually really like your spline idea. That is something I can do, although I'll need to look into splines again. I think that's what I'll do.

Thanks for the help!

This topic is closed to new replies.

Advertisement