User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11

Thread: Anti stack with SolarB's tower defence path-finding

  1. #1
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module
    Lukiester's Avatar
    Join Date
    Feb 2014
    Location
    Melbourne
    Posts
    374
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Anti stack with SolarB's tower defence path-finding

    Hi all, regarding this: https://community.clickteam.com/threads/91019-Tower-Defence-Kit-ALL-PLATFORMS Does anyone know how to add an anti stack mechanic with enemies so they dont overlap eachother. Of course for his example you dont need it as they cant stack but for my example i have a moving target.

    Thanks so much, Lucas.

  2. #2
    Clicker Fusion 2.5iOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    SolarB's Avatar
    Join Date
    Feb 2012
    Location
    Melbourne
    Posts
    905
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Hey, thanks for checking out my example

    Unit overlap has always been the bane of developers, I think I read somewhere that even the Starcraft devs came up with hacky ways of overcoming this and you'll still see unit glitches here and there.

    Maybe the best way here is to somehow check if there's a unit already on a tile and to stop the nearest unit(s) from moving there. I'm not sure how this will work and unfortunately I don't have the time to experiment but if anyone has any ideas please share.

  3. #3
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module
    Lukiester's Avatar
    Join Date
    Feb 2014
    Location
    Melbourne
    Posts
    374
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Ah right, thats a shame. Thanks a lot for your help and especially your example.

  4. #4
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module
    Lukiester's Avatar
    Join Date
    Feb 2014
    Location
    Melbourne
    Posts
    374
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi, actually i could really use some help (im releasing a game in 2 days aha), why does increasing the speed cause enemies to go out of control? Attachment 27564

    Thanks so much.

  5. #5
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module
    Lukiester's Avatar
    Join Date
    Feb 2014
    Location
    Melbourne
    Posts
    374
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Oh sorry, here is the file: TD Template 1+player 2.mfa

  6. #6
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Posts
    1,305
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Not sure about why enemy movement goes wrong above a certain speed, but I'd guess it relates to your "MoveTimer" variable.

    Having said that, I can see how the pathfinding engine as a whole could be made very much more efficient.
    Basically, you want a single path array, which is shared by all enemies, and which contains the distance of each map tile from the nearest player. You store the positions of each player, and then flood fill outwards from each one, at the same rate - and store the iteration each time.

    So on the first loop, you write a "1" at the position of each player. The next loop, you store a "2" adjacent to those. The next loop, you store a "3" adjacent to each cell with a value of "2" - UNLESS that cell already has a value lower than 3 (but not 0, which would mean "un-visited"), or it's an obstacle. And then you just keep going until you can't go any more!
    The trick is to keep an ordered "stack" of cells to visit, to make sure you never visit any cell twice - and for that you can use a list object.

    I may try to cobble together a quick example, but I've got quite a lot on today...

    You can also expand on this system, by giving map squares "weights". For example, an empty space takes a zombie 1 second to walk through, so it has a weight of "1". An unbreakable wall has a weight of "99999999" (ie. infinity). A breakable door might take 5 seconds to break down (and then another second to walk through), so it would have a weight of 5 + 1 = 6.

    Alternatively, for something as dumb as a zombie, you might want to compare the walking distance using the calculated path against the straight line distance - and then if the difference is quite low, the zombie will move intelligently, but if it's greater (more of a complex detour) the zombie will just bang its head against the wall or give up. Personally, I think it's really nice when enemies in games are not just differentiated by stats and special abilities but by their AI behaviour (brave, cowardly, aggressive, passive, intelligent, stupid, work together, communicate, use items, use the environment, etc).

  7. #7
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module
    Lukiester's Avatar
    Join Date
    Feb 2014
    Location
    Melbourne
    Posts
    374
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi thanks so much for the reply. Have you attempted to have more than 1 target before? Weirdly i can make the enemies go faster if i duplicate line 106 but am only able to double the speed every duplicate. Yeah that is a good idea but i think right now id just like a fundamental working system. I have made bullets only capable of harming 1 zombie at a time which makes the stacking a bit less of a problem yet i am still having big troubles with the speed.

    Thanks so much.

  8. #8
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Posts
    1,305
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Yes, I've had something like this working before for multiple targets, but only in a squad level turn-based strategy game, so performance was never a serious concern.
    After a little experimentation, I've come to the conclusion that for AI that completely searches a map the size of yours (90 x 50), it's simply not feasible to do it in realtime (all in one game loop) without slowdown, so you need to spread the calculations out. The zombies will be slower to react, but slowdown can be eliminated that way. I've also cut down the maximum pathfinding range, which helps a lot - you could always use dumb "obstacle avoidance" for zombies far away from any players. Or you get rid of that part and tweak the other parameters to get the kind of performance you want...

    I've made a little example of the pathfinding method (not the actual zombie movement) here:
    https://1drv.ms/u/s!Atq7cUIJ7uexjz1-...nv3MK?e=2g88xf

    It's fairly well commented, so shouldn't be too hard to follow

    The movement stacking should be straight forward. You just want to have each zombie check its distance from the nearest player (using the pathfinding method), and then move them in order, starting with the one closest to a player (any player - it doesn't matter which) - and don't allow any zombie to move into a square that already contains another zombie.

  9. #9
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module
    Lukiester's Avatar
    Join Date
    Feb 2014
    Location
    Melbourne
    Posts
    374
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Wow thanks so much, appreciate it So at every position on the screen there is a route to a player? Its defiantly fine with the slower reaction time as they are zombies . I do understand some of it but not enough to implement it, sorry. I think im going to just use the duplicate speed as i am so pressed on time but i would defiantly love to implement this as soon as possible.

  10. #10
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Posts
    1,305
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    I just modified my previous example to use an array instead of a list (might be faster?), and took out all the graphics that aren't mine.
    https://1drv.ms/u/s!Atq7cUIJ7uexjz7n...wKV72?e=Ff8qeb

    I haven't looked into the method you're using very thoroughly, so I'm not sure how different it is.

    With the method I'm using, there is a map (array) that stores the distance from every single map tile to whichever player is nearest (except for tiles which either contain obstacles or are in areas sealed off by obstacles, which will have a value of zero). To move from any tile to the nearest player, an enemy simply needs to check the map values for the four tiles directly adjacent to its current position, and move to the one with the lowest value, and then keep repeating every time it reaches a new tile.

    Using this method, performance is proportional to map size, but not influenced by the number of enemies - so it's perfect for something like a Tower Defense game, where there is typically a smallish map, but many, many enemies.

    In games with fewer enemies and larger, more open maps, it's more efficient to use the A* pathfinding algorithm, which is "directed" and doesn't explore the entire map looking for paths.

Page 1 of 2 1 2 LastLast

Similar Threads

  1. Tower Defence - Unit Tower Help
    By Malachi32 in forum Fusion 2.5
    Replies: 11
    Last Post: 31st October 2017, 11:34 AM
  2. Tower Defence Kit 1.0
    By SolarB in forum Guides, Tutorials, Examples, Widgets
    Replies: 3
    Last Post: 2nd September 2014, 04:20 AM
  3. Tower Defence Help
    By Destroyer0203 in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 1st January 2010, 12:33 AM
  4. Tower defence
    By Algul in forum File Archive
    Replies: 14
    Last Post: 1st June 2009, 12:22 PM
  5. Tower defence Range
    By Zmaster in forum Multimedia Fusion 2 - Technical Support
    Replies: 13
    Last Post: 19th October 2008, 08:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •