pathfinding problems, and other bugs

0 favourites
  • 8 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • I've been working on this game for a while now and it has to be done by mid-April. Long story short I don't have a lot of time to spend hours trying to figure this out and I'm stressed out as it is. My game is a maze, and I wanted ghosts to traverse one of the 4 paths depending on which one you chose from the drop-down menu on the title page. Each path will have it's own ghost, but for now I wanted to just get path one to work. That's failed so far, and I've no idea why. some what I think are bugs are;

    1. The default layout isn't always chosen, not sure why.

    2. path finding isn't moving along path, may be because of the cell size

    3. I was having problems with the player interfering with the ghost, and the positions shifting when both would spawn in at the same time; I think because a solid cannot be inside of a solid

    I'll end it there for time sake, but I could really use some help on this.

    There's the .capx, I hope it works, if not let me know. Thank in advance.

  • Hi Waffle

    I have looked at your capx. And if i have understood you correct, you want the Ghost to trace a route for the player to the correct exit?

    If thats the case there are some problems with your program.

    1. I dont think that "Find path" works in the "on start up event".

    So instead you can add a boolean variable to the ghost and call it "Tracing" or whatever and set it to false by default.

    Then add an event that if "Tracing = false" Then "Set Tracing = true" and "Find path(X,Y). Then if you want it to run again you can simply move its to the start position and set the "Tracing" variable back to false.

    2. The size of the ghost is way to big for your maze. The maximum size that you can use is 9, for both width and heigth and the cell size.

    An idea that might make it a bit easier, is to use a sprite instead of X,Y values when you use "find path", So if you make a sprite called "Ghost_target" for instant and then in the find path, you can simply write "Find path("Ghost_target.X, Ghost_target.Y")" then you can move it around on the layout or runtime without having to update your X,Y values each time.

  • How can you tell that the ghost was too big for the cells it currently had? I do have a problem with Booleans, as they've proven to be unreliable and trouble some in the past, so usually I just make a global variable and have it change to 0 and 1 as my "Boolean".

    These things aside, I really appreciate your help on this; you've been a great help.

  • In the latest beta you can show the grid in the editor. You can set it to 40x40 and see the pathfinding cells.

    <img src="" border="0">

    Any square with a solid object in it will be blocked so you can see there is no path to the exit. That includes the player and the ghost itself as they both have solid behavior.

    You can show the blocked cells in-game as well like this (Press 'space'):

    ghostPathfinding.capx (r123.2)

    When you say the default layout isn't always chosen, do you mean when you press run layout? That runs the layout that was last active in the editor. You can press F4 to run the first layout.

  • My best guess to why your booleans are giving you problems is most likely because you pick objects wrong, so you end up setting booleans for objects that shouldnt.

    The benefit of using variables linked to objects, is that it helps make your project a lot easier to work with, as you know that variable linked to those objects wont interfere with anything else, and can only only trigger for those objects. Also they get reset to default values whenever a new object is created, so you dont have to think about if a global variable is at the correct setting for that object. But changing it, might screw up things for other objects. So quickly you will start to loose control. However if you dont like using them i guess there shouldnt be any problem in just using globals, if you can keep an track of them.<img src="smileys/smiley1.gif" border="0" align="middle">

    Regarding the size of the ghost. Your ghost was 19x19 and had a cell size of 40. Which means that your map (layout) is divide into 40x40 squares, and each of these will be checked for whether they are "clear" for objects moving through them. If a solid object like your walls are touching one of these cells, it will be flagged as "not clear" and object can move that way.

    So if you have a map(layout) which is 100x100 pixel and make a cell size of 100, then you would only have 1 cell.If you then add a solid object with a size of 10x10 some where, it will mark the whole map as "not clear". as its covering that 1 cell.

    But if you decrease the cell size to 1 you would suddenly have 10000 cells to check for being overlapped or not. If you then add your solid object, it would only cover 10x10 (100) pixel of the 10000 pixels. Making it possible for objects to move around the map.

    However its not a good idea to set cell size to 1, its just for the example, as your computer would have to make way to many calculations when finding paths.

    A good rule of thumb is to use the largest cell size that you can get away with.

    You can read more about it in the manual:

    Path finding

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I can't figure out how you got the grid to be visible. I pressed space and everything, in game and out. I do appreciate the help though. I understand why it can't find the path, I just can't see the grid to correct it. Was it corrected in the .capx you gave me? I couldn't open that one because it said an image was missing... anyways, thanks man.

  • <img src="" border="0" />

  • Thanks for the screenshot, man. Even with that new knowledge I can't get it to work. I even tried the coding for just the ghost by itself. The ghost was a really small size, and the grid was a 10x10 I believe. I don't know what I could be doing wrong, I checked everything from the ghost to his destination and everything seems good... The only thing I can think of would be to size up the whole thing so I can get away with having a larger grid.

    Also, I pressed F4 and it still took me to the last active layout.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)