Using minetest.find_path for mob pathfinding
Yesterday I was surprised to find out that Minetest should now have a pathfinding system. I'd rather not wonder how CPU hungry such a thing is... but either way, I'd like to add an option for my mob mods to use it. Problem is that the engine only provides half of the solution, while the rest must be done in Lua and I'm not quite sure how.
From what I understand, that returns the list of positions an entity must go through. So far so good... but what's the simplest and most efficient way to make a Lua entity actually follow this array of points? How can an entity go to the first point, detect that it arrived there, then head toward the second point, and so on?
Things to keep in mind: The path and point list is constantly refreshed, to account for cases where a block has been placed or removed and the path must therefore change. The mob must also be able to adapt if someone pushes it off trajectory, for example by digging a block from under its feet and letting it fall. My mobs are otherwise based on PA's simplemobs... so currently, a mob walks toward a player it's attacking by looking toward that player (changing rotation) and being given a forward velocity.
minetest.find_path(pos1,pos2,searchdistance,max_jump,max_drop,algorithm)
^ -> table containing path
^ returns a table of 3d points representing a path from pos1 to pos2 or nil
^ pos1: start position
^ pos2: end position
^ searchdistance: number of blocks to search in each direction
^ max_jump: maximum height difference to consider walkable
^ max_drop: maximum height difference to consider droppable
^ algorithm: A*_noprefetch(default), A*, Dijkstra
From what I understand, that returns the list of positions an entity must go through. So far so good... but what's the simplest and most efficient way to make a Lua entity actually follow this array of points? How can an entity go to the first point, detect that it arrived there, then head toward the second point, and so on?
Things to keep in mind: The path and point list is constantly refreshed, to account for cases where a block has been placed or removed and the path must therefore change. The mob must also be able to adapt if someone pushes it off trajectory, for example by digging a block from under its feet and letting it fall. My mobs are otherwise based on PA's simplemobs... so currently, a mob walks toward a player it's attacking by looking toward that player (changing rotation) and being given a forward velocity.