Jump to content
  • Advertisement

Tower Defence Days 4 & 5



Day 4

  1. Actors sink into ground when dead
  2. Auto generation of waypoint paths / building plots
  3. Refactoring
  4. Failed trial with ragdoll

Day 5

  1. Run animation working
  2. Watching tutorial videos for user interface
  3. Selection of spots for building
  4. UI for selecting which towers to build
  5. Build on mouse click (with fail when full already)

It's felt like progress has slowed down, however this is partly an illusion because it is easier to see progress when graphical things change and not when behind the scenes things change. However I did have several problems with basic C# stuff (probably because I haven't really got the time or inclination to learn the language).


I have to say I don't know whether it's my lack of knowledge but I've found  C# very painful to use so far. I used it once before for a little GUI app, but here in unity it seems more like a scripting language, okay for basics but none of the unity tutorials have stuff like creating your own types (there was no in built integer vectors in the version I am using!!) and the seeming need for references everywhere is a big WTF (it is possible I should be using struct rather than class?). I shudder to think what is going on below the surface. I may even end up investigating javascript support as I don't remember that being as painful to work with. This was coupled with monodevelop not saving my files properly, I had to alter the key bindings to save all with Ctrl-S to make sure all my files were being updated.


Ideally I'd like one of these rapid engines that was programmatical rather than GUI based. Drag and drop is great for non-programmers, but I'm just finding it painful, watching 5 seconds of a tutorial video, alt tabbing to unity, finding the exact spot the guy clicked, back to the video etc etc. And works with C++. I did briefly try unreal a year or so ago but it was so bloated it hardly ran on my old machine.

Incidentally I'm finding the videos by Brackeys very useful on youtube, even if some of the stuff like lack of enums makes me groan, I know it is aimed at beginners. He goes through topics rapidly so it's less boring and time wasting...


Anyway .. back to the game. The most interesting bit has been deciding how to make paths for the enemies and plots of land for building on. There's probably a great algorithm for this, but most of the tutorials had manual map creation, so I just had a quick stab at it. At the moment I create a bunch of rectangular 'blocks' or plots of land on which to build buildings, that is not allowed to be walked on. Then I run the Floyd Warshall algorithm to find all the paths from every cell to every other (this is simple to implement). At the moment I just choose 2 far off points for the enemies to run between to create the waypoints. But with all the paths calculated the enemies could theoretically spawn anywhere.


I tried last night to get ragdoll working as it would be kind of cool to have the enemies thrown off their feet when they get hit. But I got loads of tearing with my model, something in the export it doesn't like so I may spend more time on this when I get everything else working. Getting skinned characters exported from blender in 'just the right' way seems to be a bit fiddly. Ragdoll would be kind of cool if I get to firing monkeys out of cannons with physics.

The structure of my game code still seems a tad messy with some duplication of similar classes, because I'm learning unity, I'll have to clear it up quite a bit if I release the source at the end.


Recommended Comments

Ragdoll feature would be pretty cool!

Share this comment

Link to comment

Having slept on it I now think I'll probably use something far simpler for the paths. I could just generate a few random points and do manhattan walks between them (if they don't cross). I'm not sure the game needs proper pathfinding, plus Floyd Warshall might limit the bigger map sizes as it needs lots of memory.

Share this comment

Link to comment

If I was making pre-set paths I would just set nodes at every direction change. Considering you're not dealing with something dynamic, it's a good approach. :) No reason to use anything else because the enemies are essentially running on a rail system.

Share this comment

Link to comment
9 hours ago, lawnjelly said:

manhattan walks

What exactly is manhatten walks?

Share this comment

Link to comment
17 hours ago, Awoken said:

What exactly is manhatten walks?

Sorry awoken I was away most of yesterday. Manhattan distance is a cheaper way of calculating distance between 2 points, where x and y is the x and y difference : Manhattan distance is x+y, Actual distance is sqrt(x_squared + y_squared). Manhattan is so called because it is on a grid like the city Manhattan I believe. So I invented the term Manhattan walk just there to be walking a path along the x and then the y (or vice versa) along a grid instead of taking a straight path as the crow flies. :)

Share this comment

Link to comment

If I understand correctly then if we're let's say measuring distances between 2 points on a grid then the Manhattan approach would be better suited.  I'm assuming there are some instances where Manhattan would return results that are incorrect?  Or does the Manhattan approach always work?

Share this comment

Link to comment


This article explains better than I can. The most basic distance is the shortest distance between 2 points, this is Euclidean distance (as the crow flies). You get manhattan distance as explained earlier, although I made slight booboo it is abs(xdiff) + abs(ydiff) as negative values can cancel out. The square in pythagoras for euclidean distance takes care of this for you. There is also chessboard distance which works on a grid but allows diagonal moves as well as just up and down.

You can combine approaches, there are no rules. Like use euclidean distance on a grid. In fact we could also potentially use bezier curves for the paths between the waypoints, it is slightly trickier to find the grid squares these cover though. You can also have a proper steering system for enemies, but then you have to deal with the numerous cases of enemies colliding with objects, which you avoid completely if you have them on rails (except for colliding with other enemies which I am not dealing with as yet).

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 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!