Solved Get block infront player?

Discussion in 'Development' started by iCirgio, Mar 10, 2019.

  1. iCirgio

    iCirgio Witch

    Messages:
    70
    GitHub:
    lolnova
    How do I get the block infront where the player is facing?
     
  2. KielKing

    KielKing Baby Zombie

    Messages:
    160
    GitHub:
    kielking
    do you mean get the block where the player's crosshair is looking or just the block in front if the player's direction
     
  3. iCirgio

    iCirgio Witch

    Messages:
    70
    GitHub:
    lolnova
    Block infront players direction
     
  4. Levi

    Levi Zombie Pigman

    Messages:
    678
    GitHub:
    captainleviftw
    What corsair? What if they don't have split touch enabled?
     
  5. KielKing

    KielKing Baby Zombie

    Messages:
    160
    GitHub:
    kielking
    if they don't have split touch enabled on mobile, if you want to know where the crosshair is, it will still be the center of their screen
     
    Muqsit likes this.
  6. KielKing

    KielKing Baby Zombie

    Messages:
    160
    GitHub:
    kielking
    I think adding $player->getDirectionVector() to the player's position would work
     
  7. Muqsit

    Muqsit Wither Skeleton Verified

    Messages:
    1,483
    GitHub:
    muqsit
    You can use
    PHP:
    $player->getTargetBlock($distance);
    That accounts for player's direction vector (aka crosshair).
     
  8. KielKing

    KielKing Baby Zombie

    Messages:
    160
    GitHub:
    kielking
     
  9. Muqsit

    Muqsit Wither Skeleton Verified

    Messages:
    1,483
    GitHub:
    muqsit
  10. KielKing

    KielKing Baby Zombie

    Messages:
    160
    GitHub:
    kielking
    he said he doesn't want to get the block the player's crosshair is looking at
     
  11. GamakCZ

    GamakCZ Baby Zombie

    Messages:
    169
    GitHub:
    GamakCZ
    use Player->getDirection();

    Code:
    0: 'x+'
    1: 'z+'
    2: 'x-'
    3: 'z-'
    
    PHP:
    /** @var Vector3 $vec */
    $vec null;
    /** @var Player $player */
    switch($player->getDirection()) {
        case 
    0:
            
    $vec $player->add(1);
            break;
        case 
    1:
            
    $vec $player->add(001);
            break;
        case 
    2:
            
    $vec $player->subtract(1);
            break;
        case 
    3:
            
    $vec $player->subtract(001);
    }
     

Share This Page

  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.