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

Get entities where player look

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

  1. Nora1903

    Nora1903 Slime

    Messages:
    82
    GitHub:
    cuongvnz
    Yes, like the title, are there any ways to get entities in the look direction of player ?( linear)
    Thanks
     
  2. Darku

    Darku Spider Jockey

    Messages:
    49
    GitHub:
    DarkWav
    Its not very easy, but you could use the getDirectionVector() function.
     
  3. Nora1903

    Nora1903 Slime

    Messages:
    82
    GitHub:
    cuongvnz
    Yes, absolutely
     
  4. Nora1903

    Nora1903 Slime

    Messages:
    82
    GitHub:
    cuongvnz
    Waiting for help......
     
  5. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    By looking at the documentation of the VoxelRayTrace class it could be what you need:
    https://github.com/pmmp/Math/blob/95ae5600328ed2add44c0bc830a68d3660e9e0ef/src/VoxelRayTrace.php#L38

    You'll want to iterate over the returned Generator instance like this:
    https://github.com/pmmp/PocketMine-...c014aab/src/pocketmine/entity/Living.php#L822

    And for each Vector3 in the loop you check if there is an entity nearby using a tiny maxdistance, and probably break the loop when you found an entity. This could be useful to check it:
    https://github.com/pmmp/PocketMine-...6bb06630/src/pocketmine/level/Level.php#L1960
     
    SleepSpace9 likes this.
  6. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    no need for all these above...
    PHP:
    /** @var Entity $player */
    /** @var Player $player */
    $entity->setRotation($player->yaw$player->pitch);
     
  7. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
  8. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    I've got it now...
    Spawn an invisible human on the place the player is watching at.
    Calculate the distance and get the yaw and the pitch using atan2()
    Then set the rotation and remove the entity from the packet.
     
  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.