mojira.dev
MC-21109

Pathfinding is fundamentally flawed (it strictly follows the grid)

I will say right now that both MC-12427 and MC-4661 are included in what I am about to report. However, I am reporting exactly what the problem is, how they are in reality the same issue, examples of other pathfinding issues which also occur, and how it could all be fixed with a single theoretical solution. It seems sort of conceded to ask if they could be consolidated into this report, but I feel like this single one is more constructive than a bunch of little ones out there which are all symptoms of the same bug.

The problem
The problem with the pathfinding in Minecraft is that is uses a strictly grid-based system. This would be okay except that collisions are not as strictly grid-based. Entity movement accounts for this, but pathfinding does not. The consequences of this are far reaching. Basically there are many ways in which an entity may conclude that it cannot move when in reality it can and vice versa. Fixing this bug would make farming less frustrating and hiding from monsters much harder. Let me explain each of the four images inside the larger image I posted.

1. Mobs (the creeper) get stuck in northwest corners
This is a combination of things. For one thing, entities begin pathfinding from their northwest corner instead of their center. For another, they do not take into account collisions properly. This means the creeper pictured begins his pathfinding from inside the corner fence. This creeper believes he can travel both north and west because it is air, and he cannot travel either south or east because they are fences. All four of these assertions are wrong. If he were to analyze collisions instead of just the grid he would know this.

2. Mobs are incapable of passing through half slab gaps
Some people like and utilize this, but it is a flaw. The creeper knows he can pathfind through the center of the hole, but reasons he is too tall to put his feet through the center and his head through the half slab. This is false. He does not take into account where his feet will land, and the same can be said about his head.

3. Mobs, especially small ones, get stuck inside walls
The picture is a special case in which the sheep has his northwest corner inside a wall. He can clearly step back and walk through the opening in the fence to my character, but he believes the fastest way is to walk through, because he is already "inside" the fence and does not take collisions into account. This same thing will happen with small entities far more frequently because their entire collision box can fit inside the fence block. This makes it a pain to lead animals along/through fences and other thin walls.

4. Mobs cannot navigate through gaps between blocks
This is the same issue as the creeper who cannot walk through the half slabs but in the x and z dimensions. If the chicken were to acknowledge the size of its bounding box and which blocks it would collide with, it could reason that it is possible to fit through the gap.

More details
It has recently come to my attention that small entities like chickens cannot pathfind out of fence corners even if they are told they can pathfind literally anywhere. This is because they cannot draw a vector out of the fence wireframe without concluding they will collide with it.

Theoretical solution
Ideally, if the code could be more double-based, relying on the actual bounding box, this problem would be fixed in all instances. But, unfortunately, that would likely require a significant amount of processing. Instead, it is probably best to add more conditions to the code which allow pathing along but not through fences.

At the very least, changing pathfinding so that entities begin from their center should fix situations 1 and 3 (MC-12427 and MC-4661 respectively) for the majority of creatures (everything but babies, silverfish, and chickens).

Related issues

MC-1606 Mobs unable to move in slabbed house MC-3149 Mobs do not realize that they can move between fence posts next to nether brick fence. MC-11614 Mobs don't walk throught 2 block high door ways MC-23671 Cow Mob Path Finding Blocked MC-56317 Silverfish/Endermites/Cave Spiders not pathfinding through half-slabs (DUPLICATE) MC-83644 Mob pathfinding AI gets confused with glass panes MC-95323 fences, carpets and mob ai MC-109393 Llamas cannot climb properly, and constantly fall. MC-119232 Villagers cram into a certain corner MC-124539 mob path finding wraps around the edges of blocks that do not obstruct its path to the player MC-170368 Silverfish react weirdly around slabs. MC-188959 Zombies cannot go through carpet and block MC-188997 Tamed cat's pathfinding breaks when near a a villager house with glass pane. MC-190227 Mobs can't pathfind through fence corner gaps MC-190326 Infernal mobs strangely fight at the distance between the holes. MC-196974 Mobs cannot move through bamboo. MC-200247 Silverfish cannot hit players that are next to iron bars/glass pane MC-201009 Rabbits breaking MC-262922 Mobs cannot pathfind between walls and fences MC-265930 Mob doesn't move/pathfind closer to the fence to hit the player, even if they would be able to hit the player if they did MC-267501 Mobs with high value of generic.step_height are unable to step up fence or wall MC-279867 Villagers are not recognizing the fence gate as a path they can take

Attachments

Comments

migrated
[media][media][media][media][media][media]
migrated

PLEASE.

Thank you for explaining – and showing with simple pictures – exactly what's going on.

PLEASE, Mojang, this and 2025 – please make these, and similar issues, the focus of your next patch level. Yes, I'm asking for 1.7 to be the raid release (raid = bug spray)

migrated

Can confirm.

Ezekiel

Is this still a concern in the current Minecraft version? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.

migrated

I tested this bug in Creative Singleplayer also and can confirm it still exists in 1.6.2.

Torabi

Do you have any idea what the computational cost of pathfinding is? A lot of games pre-calculate and store pathing information for the terrain in order to reduce the cost of finding a path. There are certainly improvements that could be made, particularly to solve the sort of problems you mention, but you're oversimplifying the problem a great deal.

migrated

@Torabi
No, I have no prior knowledge of the computational cost of pathfinding, but I do have a decent guess. And I do understand the challenges of pathfinding in a dynamic environment.
I do think I oversimplified the theoretical solution. Having read the pathfinding code thoroughly now, I am disappointed to say that I doubt it can function perfectly ever. Changing it from int based to double based would require exponentially more points, memory, etc. I think the only way the problem has any chance of being solved in a remotely optimal way is by continually adding even more conditions to the code that basically say "in this very specific situation, do this".

migrated

Is this still a concern in the current Minecraft version 1.7.2 / Launcher version 1.3.4 or later? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.

migrated

Yes, this affects all versions up to the most recent snapshot, 13w48b. This bug would require a very significant code change to fix.

Ezekiel

Is this still a concern in the current Minecraft version 1.7.4 / Launcher version 1.3.8 or later? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.

migrated

This affects all versions up to snapshot 14w03b.

migrated

I can confirm in 14w08a with the stuck in NW corner part

migrated

Is this still a concern in the current Minecraft version 14w18a / Launcher version 1.3.11 or later? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.

migrated

There has been no rewrite of the pathfinding system. I can still observe this issue in 14w18b.

migrated

This happens with silverfish, cave spiders and endermites as of snapshot 14w21b.

migrated

I may be experiencing something similar to this in 14w snapshots (21b,25a,25b). I have two snow golems (which are NBT tagged to be invincible). They WERE attacking a baby Zombie with snowballs, so I named the baby so it wouldn't despawn. This all was happening near a corner of Nether brick fence, and somehow the little Zombie was pushed into the corner. The Zombie does not move (and being a baby it is immune to sunlight) and the golems aren't throwing stuff at it. This may be a result of how small baby Zombies are, because they can fit entirely into the hit box of a corner fence.

I think the fence is a northeast corner. I can attach screen shots if needed.

I think that this shows a fundamental bug in the AIs of at least 2 mobs.

Torabi

@unknown, that sounds like MC-7360.

migrated

I looked at that bug, and it is basically the same as this one, but this bug report addresses the root cause (pathfinding is flawed). To be more specific, the zombies have the goal of reaching a villager that is in a space occupied by a partial block like a glass pane, fence, or half slabs. Zombie pathfinding (like every other mob's pathfinding) isn't capable of utilizing the empty space that a partial block doesn't use, so the zombie behaves as if the entire space is solid and impassable.

migrated

I think it warrants a "relates to" label.

galaxy_2alex

Is this still a concern in the current Minecraft version 1.8.1 Prerelease 3 / Launcher version 1.5.3 or later? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.

migrated

Of course it is. It's pretty obvious. Reopen.

galaxy_2alex

Reopened, thanks

migrated

Confirmed for 15w43c & 1.8.8.

migrated

Confirmed for 15w44a.

migrated

Confirmed for 15w46a

FaRo1

Can confirm this for carpets on fences.

SunCat

Partly confirmed for 1.9.1-pre3
All fence problems (1, 3 and 4 pictures) are fixed, slab problem is still there. Also I found another problem (2016-03-19_13.04.06.png)

FaRo1

I suppose in the new picture no mob moves on its own?

migrated

Also noticed lately that mobs don't go through open iron doors (creepers and zombies mainly).

Gatinh0

More observation of path-finding errors:

I observed mobs not realizing they can walk around a fence post. They can see me, but they stay behind the post and never come closer to me, even though they could.

I've included screenshots of various mobs getting stuck in the same place like this.

Granted the screen shots are of range-attack mobs like witches and skels, but creepers and zombies were also getting hung up there. I just failed to screen shot the zombies and creepers doing it. But hung up where they are, even the range attacks were useless. The witch's bottles were breaking on herself, and the skel arrows couldn't get past the fence post.

 

[media][media]
migrated

This is still happening in 1.14.4.

Orbic

Still in 20w12a.

Orbic

Still in 1.16 Pre 3

migrated

I think this might fit better on the suggestion/feedback site rather than the bug tracker?

migrated

I don't believe so, because it causes passive mobs to wander away in the same direction or bunch up in corners of fenced in areas, and that is clearly a bug/unintended behavior.

migrated

20w46a

migrated

(Unassigned)

Confirmed

Normal

Mob behaviour

collision, fence, north-west, pathfinding, pathing

Minecraft 1.5.1, Minecraft 1.5.2, Minecraft 1.6, Minecraft 1.6.1, Minecraft 1.6.2, ..., 1.16 Pre-release 5, 1.16 Pre-release 8, 1.16.1, 1.16.2 Pre-release 1, 1.16.3

Retrieved