GMS 2 Object, which follows player by the shortest route in a platformer

P

Pedau666

Guest
Hi, I am trying to make object which will follow the player using only his platform abilities, by this I mean by jumping and walking. Not going through the walls like objects in my attempts did. Do you have any hints how to make this work?
 

NightFrost

Member
Not an easy task unfortunately. You'd need to run an A-star pathfinding algorithm across a graph that represents your platforms (with special consideration to jump and dropdown connections). The builtin mp grid commands aren't really sufficient because they assume a grid-shaped graph with uniform edge length. Well you could use it, but maybe 90% of the nodes would be redundant and just slow down pathfinding. You also could write a "dumb" shortest-path seeking enemy that just approaches the player and jumps and drops when neccessary, but those cannot find alternative routes and will make futile headbutts against dead ends until player moves into a position they can reach.
 

TheouAegis

Member
Or maybe right something along the lines of a complex Djikstra's algorithm but instead of treating walls as obstacles to walk around, you'd treat them as normal space if and only if they can be jumped over. Likewise with ladders. In other words, only obstacles which you have no way of getting around would in fact be treated as obstacles. You could then just let the AI follow the path laid out by the algorithm and handle the terrain issues as it comes to them.
 

pixeltroid

Member
Hmmm... Some time ago, I had a glitch where there were 2 instances of my player in my game. The second player would perfectly follow me around and would not get stuck in walls and such.
 
P

Pedau666

Guest
By now I already did some simple coding to make the object follow the player but how to make the object not jump continuosly and make it jump only when it needs to jump over the obstacle? Do you have any advice?
 
Top