Closely relates to MC-87093, however a "tracking" animation is not necessarily present; zombies do not show the arm animation problem from that ticket yet still exhibit this other behaviour. I cannot find any other tickets that describe this behaviour after searching.
The bug
When a hostile mob has line of sight to an entity they are targeting but is physically incapable of reaching them, they will repeatedly turn to face the entity and then back to the direction they were originally facing.
How to reproduce
A setup is shown in the attached screenshots featuring the player standing on a block as to be one block higher than the mob, which is trapped in a hole that allows them to see but not escape. Standing on the block should highlight the behaviour.
Expected results
The mob should either act normally as if no player is present, or continuously stare at the player they're interested in.
Actual results
The mobs appear to switch between acting normally and attempting to reach the player, causing them to nod strangely.
Related issues
is duplicated by
relates to
Attachments
Comments


These screenshots do not show the issue. Please attach a video.

Video should be attached. Here's a youtube link in the event that it can't be played: https://youtu.be/q30lkcwE6FM

Thank you. Edited the title to remove "turn away" as it made it seem like the mob was spinning in place.
Can confirm in 1.18.2. It's important to note that this issue can be seen when hostile mobs target any entity and not just the player.
[media]
I think this is related to my comment on MC-198068, but to summarize, the AI that controls them looking at their target is the same class that makes them pathfind to and attack their target, which keeps starting and resetting when they cannot find a path to the target, thus causing the mobs to briefly look at and away from the target.

This bug title is inaccurate, as even when Zombies can pathfind to you and are continuosly attacking you, they still constantly turn away and then look at the player again
I guess it all comes down to an issue with the pathfinding
Can confirm in 1.19.
Can confirm in 1.19.2 and 22w42a.

In 1.20

In 1.20.1 and 23w32a