ID:273830
 
Whenever I use walk_to() it never checks to see if it can actually move to the tile and instead prefers to spaz around the tile if it can't. What's the deal? How can I just have my mob stand still if it can't move there?
The thing about walk_to() is it doesn't actually have any sort of pathfinding. It just steps towards its destination until told to do otherwise. Sliding around all over the place when something is in the way is normal behavior.

If you want a mob to stop moving when it can't reach its destination you'll have to add hooks to check for that. The quickest and easiest way to do this would probably be to keep track of the distance between the mob and its destination. If the mob is not getting any closer to its destination, stop movement. If the mob or destination changes location, start movement again.
In response to SuperAntx
Thanks for that. I guess a real path finding library could well be in the foreseeable future. Till then... Ugh... Haha
In response to Kyle_ZX
There are plenty of pathfinding libraries available here on BYOND.

Geldonyetich's Easy AStar should be simple enough to jump right into. If you're interested in reading more about the A* search algorithm you could check out the Wikipedia page. There's also a short beginner's guide, it has a few diagrams which really explain what's going on.
In response to SuperAntx
SuperAntx wrote:
The thing about walk_to() is it doesn't actually have any sort of pathfinding. It just steps towards its destination until told to do otherwise.

walk_to does use pathfinding, it's walk_towards that doesn't.
In response to Kyle_ZX
Kyle_ZX wrote:
Thanks for that. I guess a real path finding library could well be in the foreseeable future. Till then... Ugh... Haha

If the mob can't reach the destination, most pathfinding functions will just return that there's no path and the mob won't move at all.

There are a few ways you can handle this.

1. Don't call walk_to with an obviously unreachable destination (ex: a dense turf). If you want the mob to move to an unreachable tile, pick an adjacent turf that's not dense and have them walk_to that turf.

2. Use walk_to's third argument to specify how close the mob needs to get to the destination before movement stops. You could tell the movement to stop when the mob gets within a tile or two of the destination, then call step_towards() a couple of times so that if the destination can be reached, the mob still gets there. But if it can't be reached, it doesn't keep moving around.

3. As SuperAntx suggested, check to see that the mob is actually making progress towards the destination. This can be difficult because when following a path the mob might sometimes move away from the destination, so you can't go based on distance alone. You'd probably need to keep a list of tiles recently visited by the mob and make sure it's not repeating too many tiles.
In response to Forum_account
Forum_account wrote:
walk_to does use pathfinding, it's walk_towards that doesn't.

It doesn't actually find a path from one point to the next. All walk_to() does is continually step towards a target while sliding along small obstacles. Anything using it will get stuck running into walls, it can't plot courses around them.
In response to SuperAntx
SuperAntx wrote:
Forum_account wrote:
walk_to does use pathfinding, it's walk_towards that doesn't.

It doesn't actually find a path from one point to the next. All walk_to() does is continually step towards a target while sliding along small obstacles. Anything using it will get stuck running into walls, it can't plot courses around them.

Try it out. It actually does find a path. If you've found a case where it fails to move around an obstacle, that's a BYOND bug.

I just tested it and it works fine for this:

    ###########################
                              #
                        mob   #    destination
                              #
    ###########################
In response to Forum_account
That's interesting, I just went and tested it.

Apparently it doesn't check the contents of the turf for dense atoms, it only checks the turf itself.