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

Solved Get block infront player?

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

  1. iCirgio

    iCirgio Slime

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

    KielKing Zombie

    Messages:
    245
    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 Slime

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

    Levi Skeleton

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

    KielKing Zombie

    Messages:
    245
    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 Zombie

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

    Muqsit Chicken

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

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
     
  9. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
  10. KielKing

    KielKing Zombie

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

    GamakCZ Zombie Pigman

    Messages:
    598
    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);
    }
     
  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.