Getting location in player's direction

Discussion in 'Plugin Development' started by HamOmlet, Oct 23, 2012.

Thread Status:
Not open for further replies.
  1. Offline


    Let's say I'm holding the location of a player and would like to check if said player's location was within two blocks of another player's location in the direction they're facing. I'm not too good with vectors and was hoping for a few suggestions.
  2. Offline


    I'd just like to add a little somethin' I found: I could get the blocks within a player's line of sight, but I still need to check if the block in question is in the player's direction. The below code sets an example:

                final List<Block> blocks = player.getLineOfSight(null, 2);
                final int hiddenX = location.getBlockX();
                final int hiddenY = location.getBlockY();
                final int hiddenZ = location.getBlockZ();
                for(Block b : blocks) {
                    if((b.getLocation().getBlockX() >= hiddenX)
                            && ((b.getLocation().getBlockY()) >= hiddenY)
                            && (b.getLocation().getBlockZ() >= hiddenZ)) {
    The next part deals with grabbing the player's direction, but I'm not sure what I'd do after that point. Any tips?
  3. Offline


    there is a Distance thing, so i could do if (player.distance >= 2) (so you would have to get BOTH players. not sure how you could do that)
Thread Status:
Not open for further replies.

Share This Page