How do I use the pathfinding behavior in a platformer?

1 favourites
  • 7 posts
From the Asset Store
10 Retro songs ideal for platformers or farming games
  • Hi. As the title suggests, i'm trying to create an enemy that can pathfind to a preset location (determined by a sprite), but the behavior currently is pathing far above the ground, and as such the enemy is practically neutered and actually path to anywhere (as well as continuously jumping up and down while trying to align itself directly to the path before continuing) any adivce? i'd like to get it to be able to jump over gaps, do a bit of platforming, that's really about it.

  • Man I have sunk a couple of hours into this problem and I still have no idea where to even begin :D It's really not an easy problem depending on how complex you want it. I'd argue the build-in pathfinding behavior is not suited for this type of problem. I've personally never managed to solve it.

    The basic idea is building a nodetree with connections, then use A* to find a path through that tree. But as to how to have the enemy properly traverse along the path... no clue.

    Maybe now that I have a bit more clue about js I could try again but this is rough.

    For a much more basic implementation. A handful of raycasts can do the trick.

    -Move towards the target sprite (either left or right)

    -Shoot one ahead of the enemy, if it hits a wall -> jump

    -Shoot one down from the enemies feet, if it doesn't hit anything there's a pit -> jump.

    This is crude and will not work for anything that requires more complex pathing.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I tried generating a bunch of nodes, then having it walk towards the nearest node, then delete it, and then go through it again, but it only ever worked going in one direction, and i gave up on that after a little while.

  • Also, unrelated to what i called you here for, but the enemies currently act as one- if the state of one changes, they all change (despite my best efforts to prevent this). Please remind me how to keep their states separate (it is all done with instance variables, but i am stupid)

  • I tried generating a bunch of nodes, then having it walk towards the nearest node, then delete it, and then go through it again, but it only ever worked going in one direction, and i gave up on that after a little while.

    I have been working on a platform pathfinder, but the way the default pathfinding works in construct 3 causes a lot of bugs and has very little control over it. It works most of the time.

    I am trying to get it to work with EasyStar Addon wich so far has much better performance and no issues so far.

  • Also, unrelated to what i called you here for, but the enemies currently act as one- if the state of one changes, they all change (despite my best efforts to prevent this). Please remind me how to keep their states separate (it is all done with instance variables, but i am stupid)

    Hi!

    I dont know what are you doing exactly but beware te "else"'s. Sometimes is necesary to use "if X is even" and "if X is odd" instead "i X is even" and "else".

    Use "for each"s too if necessary

    About the post main theme:

    I've never do it, but maybe if you set "custom obstacles" and "terrain cost" to some invisible sprites and make a "map for the platformer pathfind" above the games map it would help

  • Ah, I didn't realize this topic was so old. Oh well, this is still relevant.

    One way I've found works well is to make a gradient from the top of the platforms up to the jump height. Then with that we can encourage paths to be found closer to the floor and not try to go up past the jump height. Here I used it with Dijkstra's algorithm because I wanted paths from every location to one point. You could used Astar instead for a single start and goal too I suppose.

    It doesn't replicate precision platforming so enemies do fall into holes and miss jumps, but it will get to the player after multiple tries in most cases.

    dropbox.com/scl/fi/z6dlthcsp7ihqvb1wv83n/platform_pathfinding2.capx

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