Pathfinding Quesiton

0 favourites
  • 4 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • So I'm using EasyStarjs for tilemap for my pac man clone game. I got it to work, but i'm having trouble figuring out how to prevent the ghost from turning around. The system works fine. the ghost chase continuously, but I would like to prevent them from being able to change direction so immediately. Any ideas on how I could implement this?

    Ive tried setting the tile that the ghost is previously on to unwalkable or the cost to max. I cant seem to get it to work?

    There also seems to be a problem where the behavior cant choose between two paths with the same cost so it just goes through both.(In an attempt to recreate this problem. It seems that this has to do with the ghost attempting to change direction at a spit section. So I believe preventing the ghost from turning around will stop this issue.)

    I will be setting up a less messy file for sharing.

    Here is a link to the file dropbox.com/s/7v5hixv0c90xx2n/Pacman%20test.capx

  • I did some tweaking in your file, like changing the calculation to synchronous and forcing calculation immediately after pathfinding calls.

    I also hacked in a mechanism that will make the ghost unable to reverse direction unless the euclidean distance is lesser or equal than 3 tiles. It's not perfect, but at least the ghost won't be changing direction as much. :)

    dropbox.com/s/gdicr9qc3hc4uce/Pacman%20test.capx

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I didn't expect you to do the work for me.

    I see you added a previous instance to the ghost.

    You added this code <abs(Ghost.X - Player.X) + abs(Ghost.Y - Player.Y) <= 96>

    Not sure what 96 was to mean.... but I think i get the gist of it...I change 96 to the grid size.

    but you did what I wanted to do, and had tried but you manage to make it work. I bow to you. Thank you!

    I had a lot of useless code that I used for other reason that I forgot to delete, which is why I attempted to set up a less messy file. lol I realize its still messy.

  • abs(Ghost.X - Player.X) + abs(Ghost.Y - Player.Y)

    This expression is the Euclidean distance between the player and the ghost, and 96 is the size of 3 tiles. So the "fake" obstacle is added only when this distance is less than 3 tiles long.

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