B Def Tower Defense

https://vimeo.com/61098010

B Def, Bot Defense, is a tower defense game I’m having fun with. Just slapped this video up to my site and figured I’d share some of the fun with the Unity community.

In B Def you can pretty much place a tower anywhere as long as nothing is currently occupying the space and it doesn’t block the path from the entrance to the destination. I’d say a good 80-90% of the work left here is modeling, texturing, animating and balancing. Most of the code is done, just need to program a main menu, in-game menu and level loading as this is currently the only level. Also need to work out pricing the different towers. B Def doesn’t have money, instead you collect scrap from destroyed bots which seems to make more sense to me.

Anyway it’s a fun little project and I look forward to providing a good time for all. :wink:

looks like some good work but i would like to see something more originality in game player, rather then just the same basic type of tower defense game. I am sure you can come up with something

Nice work mate :).

A piece of constructive criticism, I’d like to see the pathfinding made a little more intuitive. I guess it’s ok to make it node based, but maybe you’d like to do it so that the agents don’t spread that much, or tend to go to the center line whenever they can. It seem a bit too whimsical in its current state. Also, have you considered using navigation meshes? It’s an increasingly used method that, while having some drawbacks, usually allows the agents to have a more logical behaviour when it comes to pathfinding. (Maybe it could have problems with tower placement though, and tower colliders should occupy entire grid cells though)

Anyway, it’s good work, good luck with it.

Thanks for the feedback. This is my first time working with A* path finding, I looked up some information on-line and decided to go with the Manhattan method because I wanted it to be nice and quick. Most of the time the agents shouldn’t separate like that, in this particular case the node that split the group had the lowest estimated distance to goal so when I placed a new tower forcing the agents to form a new path those just below the tile found it as the most likely candidate and so did those above the tile. I could certainly look into methods other than Manhattan which would give more realistic behavior such as more diagonal paths and less double backing when an obstacle is placed. I’ll also take a look into nav meshes, don’t know anything about them right now. Currently the game is not using any colliders, each tile stores information about what’s there and the towers just search through a list of nearby tiles to determine their targets.

As for something original the web player version of this game is likely going to be a standard tower defense game, however; I am considering the possibility of following up with a standalone version in which I have some ideas for 2-player networking. My thoughts on the subject are just some preliminary ideas I’m tossing around, I haven’t done any multiplayer stuff yet and a lot would need to be worked out balance wise too.

In case you were wondering the music featured in this video is not going to be in the game, just something on an album I was listening to at the time :slight_smile:

Edit: I was able to solve the problem where the group split in two by using a combination of Manhattan and Euclidean path finding methods. The Manhattan method is used initially, when there’s a tie the Euclidean method is used.

Yeah, my guess was that at some point placing the tower split the most accessible node routes between the group as well, that’s why I would suggest some sort of group mechanic, to avoid individual calculations, as they tend to split the group with adequate tower placement.

Maybe I’m totally wrong and your approach is the way to go if you’re pathfinding via nodes, I don’t know cause I’ve never really programmed pathfinding for a tower defense game, I’m just speaking what comes on top of my head, in case it’s of any use.

About navmeshes, I read a post here in Unity, I can’t recall which one was, but I can give you a link to an article, that cleared some things for me, maybe it’s useful for you: http://www.ai-blog.net/archives/000152.html

Feel free to add me to skype (sent pm)if you want, I’ll love to discuss anything game-dev related anytime.

Good job with your project : )

Happy coding!

Great article, I got a good laugh from the initial pathfinding flubs video :slight_smile:

After reading that I can see that the navmesh is definitely something I’ll be exploring in the not too distant future, but I don’t think it will fit well with my current setup. For this game I’m using a 2D matrix of tiles/nodes, to the best of my knowledge JS doesn’t have matrices so I’m actually using a JS Array of builtin arrays. Each position in the array contains a custom class, Tile, that extends valuetype. Each tile saves information about the tile such as its location in the game world, if it’s passable or obstructed, if it contains a tower and an array of agents that are currently marching through the tile.

When placed or upgraded the towers save a builtin array of tiles within their range and, at 25fps, they search through this array to find a target then stick with that target until it’s destroyed or moves out of range. The agents run my A* Manhattan/Euclidean function when they’re spawned to find a path through the game grid, each time a tower is placed or removed they’ll run through the pathfinding function again with their current position as the starting point, unless they’re flying units which ignore obstacles.

It runs pretty quick, even with 150 units in the game placing a tower causing them to run through the pathfinding script doesn’t affect the frame rate at all, although my system is lower-mid range so simply having 150 agents slows my system down to maybe 15-19 fps average. Currently it looks like I can safely get away with a good 50 agents on screen which should be plenty for a tower defense game.

Currently my upgraded A* script keeps the group from splitting most of the time, though they do sometimes split in some instances, but more logically. I’ll keep your group path in mind though and I might explore that option after I get a few different unit types in the game and study how the game plays out.

The agents move through their path using Vector3.Lerp between nodes and a variable stores their current percentage along the path by multiplying Time.deltaTime by a speed variable. I have a function setup to make sure the agents are always in their correct position along the entire path even if the game slows to unplayable speeds.

Thanks for the advice.

Tank Bot ready for Unity! :sunglasses:


Got the Tank Bot in the game, added some trees and rocks placed at random during runtime and finished up the options menu. Quick screenie:

post more gameplay videos! this is good!!!

Thanks. I’m sure I’ll get some more gameplay videos up once things have been significantly updated. I also worked on a few odds and ends here and there. Added zoom to the camera, touched up turret effects, a new explosion for the Tank Bot, fixed the pause feature so the character animations don’t jitter, etc…

Added in a new Spider Bot and am fine tuning the games balance as I go. Haven’t worked on any air units yet, probably move in that direction soon though. Currently the ground is just a single 2048x2048 texture, but I’m thinking of writing a shader so I can use a black and white stencil to mix tiled grass and dirt textures in order to eliminate some of that blurriness when zoomed in.

BDef development is progressing quite well. A few new units have been added including aerial units and the air defense towers are now fully functional. Added in a few more particle effects, a main menu and a second level is now complete. Fixed an issue with character animations being paused in the incorrect animation state if the game was paused while they were off-screen. Some balancing and a few odds and ends. Polished off a new game trailer too, enjoy:

Nice game, Looks more and more interesting every time I check out this thread. Keep up the good work.

Thanks friend, it’s a really fun project and moving along at a fairly steady pace. I took a good 3 days off to work on that trailer video, but it was a good time.

Looks good!

The environments look a little sparse at the moment though. Maybe you could use the same method that you’re using to randomly place trees and rocks to place smaller non-colliding meshes like shrubs or clumps of grass?

Keep it up.

Nice work. It was fun watching the video from the original post and then the trailer, a month later. You’ve made a lot of progress! :slight_smile:

Have you thought of adding more play mechanics? Maybe mobile towers, like Grenadier squads that can move across the battle field without having to be destroyed and then rebuilt? Regardless, the game looks very fun. I like the planes in the trailer the most. Keep working on it.

Thanks, some great suggestions all around. Personally I’d say the Tank Bot is my favorite, but I was quite pleased with how the Bomber Bot turned out.

The Tank Bot is pretty sweet, too. Do you have a link to your site? I wouldn’t mind checking it out every once in a while to see what you’re up to. :stuck_out_tongue:

Yeah it’s in my signature actually :slight_smile:

Doh. I have a tendency to skip over signatures. My bad. :stuck_out_tongue:

You have some nice games over there. I played Soul Survivor for a while, then Balls. I got addicted, and 100 years later, I had what I’m pretty sure is the highest score ever.

1215257--49624--$Balls Score.jpg

Okay, I admit. I only earned about 194,000 of my score the intended way. I exploited some natural flaws that go with the territory to get the other 1,000,000. Still, fair is fair, right? :wink: