Detecting player behind player

Discussion in 'Plugin Development' started by TheMintyMate, May 19, 2014.

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

    TheMintyMate

    I was recently going through deleting some of my old plugin creations, when i came across one unsolved plugin I made. Basically it was meant to detect if one player hit another player in the back, and if this happened an effect would occur. After analysing the code, I have now realised that I set the directions to 180 degrees. This meant if a player attacked another player, they would need to be exactly 180 degrees behind them, which is near impossible. So obviously, I need to change the code to accept a wider angle variant (say between 160 and -160). However I am not sure how to approach this. Does anyone have any suggestions? Code is appreciated :)
    - Minty
     
  2. Offline

    cfil360

    Use less than and greater than comparators. This basically tests for a half circle behind the player.
    Code:java
    1. if(degrees >= 90 && degrees <= 270) {
    2. //do code here
    3. }
     
    TheMintyMate likes this.
  3. Offline

    TheMintyMate

    cfil360
    Ok, and also, i am right in saying that 0 degrees is where the player is looking?
    Thanks :)
    -Minty
     
  4. Offline

    cfil360

    TheMintyMate yes i believe that is correct but double check.
     
  5. Offline

    TheMintyMate

    cfil360
    Ok, thanks :)
    Il test it out shortly, and il be back with feedback, thanks again :)
    - Minty
     
Thread Status:
Not open for further replies.

Share This Page