Tower Defence Days 4 & 5

Published May 09, 2018
Advertisement

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).

C#

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.

selection.jpg.cff473a311da794c130d689b9faeafda.jpg

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...
https://www.youtube.com/watch?v=IlKaB1etrik

Pathfinding

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.

running.jpg.694af01eadf1be70eee6b4e2a5bb0b83.jpg

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.

Previous Entry Tower Defence Day 3
Next Entry Tower Defence Day 6
2 likes 8 comments

Comments

Awoken

Ragdoll feature would be pretty cool!

May 09, 2018 07:27 PM
Rutin

Nice progress. :)

May 09, 2018 07:46 PM
lawnjelly

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.

May 10, 2018 04:55 AM
Rutin

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.

May 10, 2018 05:14 AM
Awoken
9 hours ago, lawnjelly said:

manhattan walks

What exactly is manhatten walks?

May 10, 2018 01:58 PM
lawnjelly
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. :)

May 11, 2018 07:03 AM
Awoken

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?

May 11, 2018 01:14 PM
lawnjelly

https://en.wikipedia.org/wiki/Distance

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).

May 11, 2018 01:33 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement