Checking if a player is behind another player

Discussion in 'Plugin Development' started by Afridge1O1, Jan 21, 2014.

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

    Afridge1O1

    I was thinking about cool little pvp like additions and a thought of one where if you hit a player from behind it does a little bit extra damage. The only problem is that I have no idea how to check if a player is behind another player. So if anyone knows could you please explain it to me thanks. :)
     
  2. Offline

    Bloxcraft

    This might work... didn't test it out.

    Code:
    Vector v = player.getEyeLocation().getDirection();
    v.setX(v.getX() * -1);
    v.setZ(v.getZ() * -1); // reverses direction
    Location l = player.getEyeLocation();
     
    for (int i = 0; i < 10; i++) { // iterate location
        l = l.add(v);
       
        for (Entity e : player.getNearbyEntities(10, 10, 10)) {
              if (e == attacker) {
                  // do stuff
              }
        }
    }
     
  3. Afridge1O1 Get the blockx and blockz position of both players and if they are different by 1 or 2 blocks, do something
     
  4. Offline

    Syd

    attacker.getLocation().getDirection().angle(victim.getLocation().getDirection()) / 180 * Math.PI;

    This gives you the angle in degree of an entity to another. You just need to add some range checks and a damage mod and you've finished a basic backstab. ;)
     
Thread Status:
Not open for further replies.

Share This Page