2

I'm trying to create a custom mob (like a zombie or armor stand with a tag) that always targets the nearest player as if it were aggressive — but without using mods or external tools.

What I want is:

  • The mob follows the nearest player like it's chasing them
  • Ideally, it works for multiple players in the world
  • Vanilla Java Edition only (1.20+)
  • Done through command blocks or functions

I've tried using /tp to teleport the mob toward players every tick, or using /execute as and facing entity @p, but the results are janky or too fast/slow. I know mobs can be made to look at players with /tp facing, but I want the movement too, and as close to natural pursuit as possible.

2
  • With datapacks alone, the only way to make the movement any smoother than teleporting every tick would be to replace the armor stand with an actual mob that will pathfind on its own. For the armor stand being too fast or slow when teleporting, it should be possible to define some speed at which the mob moves at per tick and teleport by at most that distance toward the player? you just need an appropriate; zombies move some 2.3 blocks/sec for example. Commented Jul 7 at 15:21
  • i don't have enough meat to put this in an answer, but to me the easiest solution would be to make the custom mob ride an invisible zombie with its scale being 0.0001. the main problem would then become that humanoid mobs would enter the riding animation, but that's not a problem if you use an armor stand for display. Commented Jul 8 at 8:29

1 Answer 1

2

1.19.4+

Zombies and other mobs have the unique quirk where they always target the last entity that damages them (think how zombies responds when a skeleton shoots them, for example).

Therefore a nice approach to solve this problem is to force the nearest player to the zombies to give it tiny damage all the time. Let's say the zombie is tagged with the tag follower. You can change the selector however you want.

/execute as @e[tag=follower] at @s run damage @s 0.000001 generic by @p

Run this whenever you want to change the entity being targeted, and the follower mob will change target to its nearest player.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.