Zombie/mob follow player

Discussion in 'Spigot Plugin Development' started by ElkpojoacoTwo, Aug 14, 2019.

  1. I want to spawn a zombie that follows the player that spawned it without attacking the player, and if another mob attacks the player then the zombie should attack that mob.
    I've been trying and reading many different things, I've only seen pathfinding methods and I don't really understand how that works, and when I try to do it I find out that things are way different now than they were 1-3 years ago.
    So I would appreciate if someone could explain how to do pathfinding correctly, deleting default mob goals and setting new ones, or maybe if you know another way to do this, I'd like to know anyways.
    Thank you :)
     
    #1 ElkpojoacoTwo, Aug 14, 2019
    Last edited: Aug 14, 2019
  2. Simple solution:

    Spawn your zombie and set its target to the player:
    https://hub.spigotmc.org/javadocs/b...tml#setTarget-org.bukkit.entity.LivingEntity-

    Then you want to listen for some events:
    1. Player Damage Event. if another Mob attacks the player -> Update the zombies target
      • If the target entity dies -> set the zombies target back to the player
    2. Player Damage Event -> if the player gets damaged by the zombie cancel the event
    3. Entity Target Event

    Thats basically all it takes. Simple as that :)

    If you want to customize the path finding tho you have to find another way.
     
    • Like Like x 1
  3. Thank you! :) That worked, I'd like to learn about pathfinding at some point as well though, but this helped me a lot.
     
  4. i do know a lot about that subject if you wish you can ping me
     
  5. register the zombie and make a follow class
     
  6. no... clean the path goals and add custom or from other mobs path finders :p