1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Entity follows player

Discussion in 'Development' started by #A6543, Jan 19, 2017.

  1. #A6543

    #A6543 Zombie

    Messages:
    267
    I use this:
    PHP:
    $entity $player->getLevel()->getEntity($this->pet[$player->getName()]);

    $speed 1;
    $x $player->x;
    $y $player->y;
    $z $player->z;
    if(
    $x ** $z ** 0.7){
    $motionX 0;
    $motionZ 0;
    }else{
    $diff abs($x) + abs($z);
    $motionX $speed 0.15 * ($x $diff);
    $motionZ $speed 0.15 * ($z $diff);
    }
    $entity->move($motionX$y$motionZ);

    $entity->level->addEntityMotion($entity->chunk->getX(),$entity->chunk->getZ(),$entity->getId(),$motionX,0,$motionZ);

    $entity->updateMovement();
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Don't call updateMovement
     
  3. #A6543

    #A6543 Zombie

    Messages:
    267
    That helped. And I removed move (). But now the entity isn't following me
     
  4. #A6543

    #A6543 Zombie

    Messages:
    267
    How can I make the entity follow me?
     
  5. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    It should work. What code do you have now?
     
  6. #A6543

    #A6543 Zombie

    Messages:
    267
    PHP:
    $entity $player->getLevel()->getEntity($this->ID);

    if(
    $entity != NULL) {

    $speed 1;
    $x $player->x;
    $y $player->y;
    $z $player->z;
    if(
    $x ** $z ** 0.7){
    $motionX 0;
    $motionZ 0;
    }else{
    $diff abs($x) + abs($z);
    $motionX $speed 0.15 * ($x $diff);
    $motionZ $speed 0.15 * ($z $diff);
    }
    $entity->level->addEntityMotion($x,$z,$entity->getId(),$motionX,0,$motionZ);
     
  7. #A6543

    #A6543 Zombie

    Messages:
    267
    What I wrong with this? The entity isn't following me
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.