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

Get entities near player

Discussion in 'Development' started by Nora1903, Jul 13, 2018.

  1. Nora1903

    Nora1903 Slime

    Messages:
    82
    GitHub:
    cuongvnz
    How to get entities if they are near a player ? Thanks
     
  2. Aviv

    Aviv Baby Zombie

    Messages:
    156
    PHP:
    /** @var Player $player */
    /* @var int $maxDistance The distance the entity needed to be within */
    /** @var Entity $entity The entity within the radius */
    foreach($player->getLevel()->getNearbyEntities($player->getBoundingBox()->expandedCopy($maxDistance$maxDistance$maxDistance)) as $entity){
      if(
    $entity->getId() !== $player->getId()){
        
    // $entity is within the radius of $player
      
    }
    }
     
  3. Sergey Dertan

    Sergey Dertan Silverfish

    Messages:
    18
    PHP:
    $lvl->getNearbyEntities()
     
  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.