Page 2 of 5 FirstFirst 1 2 3 4 ... LastLast
Results 11 to 20 of 45

Thread: Pathfinding on Android

  1. #11
    Please re-download the example - I just fixed a major bug that was causing it to check the same squares multiple times (in some cases, causing it to use 1000+ loops when it only needed 50 or so).

    EDIT: I've updated it again to use delimited strings instead of fixed-length strings (I just couldn't be bothered to look up which string tokenizing extensions were Android-compatible before).
    Last edited by MuddyMole; 11th April 2013 at 03:51 AM.

  2. #12
    Clicker Fusion 2.5iOS Export Module

    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    71
    Quote Originally Posted by happygreenfrog View Post
    crusher, do you think that you could make us an example? It would be appreciated if you did so.
    dPathfinding.mfa

    Here's an quick and dirty example I threw together. MuddyMole's example is excellent but will only work with one object at a time. My example is perhaps slightly more advanced but will let several object use the same "weighted map" to calculate a path to a shared destination. The only time the weight map need to be be rewritten is when the destination is changed, like if the player has moved to a new square on the grid.

    My example doesn't cover how to store the path as a string. Check MuddyMole's example for that!

    EDIT: Also, the reason I'm using two arrays for the map data is so that you can wipe the weight map and checked cells data without also erasing the tile map. If that makes sense...
    Last edited by crusher; 11th April 2013 at 02:26 PM.

  3. #13
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleSWF Export Module
    happygreenfrog's Avatar
    Join Date
    May 2011
    Location
    I.L.T.D.O.I.R (I.L.T.D.O.I.R's Location: The Dimension Of Infinite Recursion)
    Posts
    4,280
    Blog Entries
    12
    Erm, MuddyMole, I can't figure out which file is the pathfinding example. What is it called?
    My GameJolt, my Twitter. If there are awards for "'highest number of long forum posts", then I'd have probably won at least 1 by now.

  4. #14
    It's the one called "SimplePathfinding.mfa", but you shouldn't need to select the file anyway - just click the "download" button at the top.
    I'm still working on improving it though - making it more efficient and versatile (possibly allowing for a range of movement costs, instead of just clear/obstacle), and making it more self-contained so you can easily add it to an existing project.

  5. #15
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleSWF Export Module
    happygreenfrog's Avatar
    Join Date
    May 2011
    Location
    I.L.T.D.O.I.R (I.L.T.D.O.I.R's Location: The Dimension Of Infinite Recursion)
    Posts
    4,280
    Blog Entries
    12
    Ah, okay. I'll download it, now that I know what to do. By the way, crusher, your pathfinding example is great! I actually added in the ability to add walls while it's running, for something like, say, a tower defense game. Also, MuddyMole, your example is pretty good, too. However, the fastloop "Obstacles" could easily be replaced with a ForEach loop, which would make it much faster.

  6. #16
    Yeah, that isn't really part of the example - it's just that any example requires an array containing some obstacles. In practice, it would be crazy to keep re-populating the array with obstacles every time you search for a path. In any actual game, all your map data would already be stored in an array somewhere (you wouldn't even be using actives for obstacles to begin with), so you'd just load that (this is one of the changes I'm making).

  7. #17
    Clicker Fusion 2.5iOS Export Module

    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    71
    Quote Originally Posted by happygreenfrog View Post
    Ah, okay. I'll download it, now that I know what to do. By the way, crusher, your pathfinding example is great! I actually added in the ability to add walls while it's running, for something like, say, a tower defense game. Also, MuddyMole, your example is pretty good, too. However, the fastloop "Obstacles" could easily be replaced with a ForEach loop, which would make it much faster.
    Thanks! Yeah as long as you update the weight map when obstacles are added it should work fine. And depending on how complicated you need the pathfinding to be you may not need to save the path as a string. For a simple tower defense game you only need compare the weight on an enemy's current cell on the grid with the weight of the neighboring cells and walk toward the lowest one.

  8. #18
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleSWF Export Module
    happygreenfrog's Avatar
    Join Date
    May 2011
    Location
    I.L.T.D.O.I.R (I.L.T.D.O.I.R's Location: The Dimension Of Infinite Recursion)
    Posts
    4,280
    Blog Entries
    12
    Yeah, it shouldn't be too hard to make a tower defense using your pathfinding system. It's pretty cool!

  9. #19
    I got it working on my game except the units still move through each other; I had to modify it quite a bit, though. I'm sure I can get that to work too though with a bit of work. Thanks MuddyMole, you will definitely go down in the credits for your help.
    I see you.

  10. #20
    Still some work to be done, but making progress: http://sdrv.ms/YOwf5M

    I'm not likely to spend a lot of time trying to optimize it for multiple units, because I'm not even convinced it would be that useful, outside of realtime-strategy games (which I doubt the Android exporter is really capable of) or tower-defense clones (and I really don't think the world needs yet another of those).
    I'd rather try and build something suited to an Advance Wars / Fire Emblem type of game - that's been on my to-do list for ages now.

    As far as stopping units moving through one another, there's not going to be much you can do about it. You can make one unit wait until another unit gets out of its way, but there's no way you'll be able to make them take into account the movement of other units during the actual pathfinding process.

Page 2 of 5 FirstFirst 1 2 3 4 ... LastLast

Similar Threads

  1. Setting up the Android SDK for the Android Export Module
    By Jeff in forum Android Export Module Version 2.0
    Replies: 3
    Last Post: 2nd October 2013, 04:08 PM
  2. Pathfinding extensions for Android?
    By Disthron in forum Android Export Module Version 2.0
    Replies: 1
    Last Post: 11th May 2013, 06:43 PM
  3. Need Android Class Name and Android Package Name to create my facebook ads
    By paobrasil in forum Android Export Module Version 2.0
    Replies: 8
    Last Post: 17th April 2013, 04:49 PM
  4. [Building Error] Android Dialogs & Android Lights
    By ProdigyX in forum Android Export Module Version 2.0
    Replies: 2
    Last Post: 20th March 2013, 09:05 AM
  5. [Bug?] Android Object/Android Menu Combo
    By scottige in forum Android Export Module Version 2.0
    Replies: 5
    Last Post: 9th December 2012, 12:16 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
  •