Bouncing back players

Discussion in 'Plugin Development' started by messageofdeath, Oct 20, 2013.

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

    messageofdeath

    My goal is to check if a person goes out of an area and if they do they bounce back.

    What I mean by this is someone runs into a set barrier and they get bounced back in the opposite direction of which they were facing.

    I already tried getting there Velocity and multiplying it by -1.
    Code:java
    1. event.getPlayer().setVelocity(event.getPlayer().getVelocity().multiply(-1));


    Thanks in advance.
     
  2. Offline

    Assist

    messageofdeath
    You forgot to get the direction of the player.
    Code:
    event.getPlayer().setVelocity(event.getPlayer().getLocation().getDirection().multiply(-1));
    
    I'm not sure if even that will work, I'm not on my computer at the moment. If it doesn't work, tell me and I'll write the code later.
     
    apple nick 4 likes this.
  3. Offline

    CaptainBern Retired Staff

  4. Offline

    Assist

    CaptainBern
    True, and if they hit the wall while facing towards the opposite way, they might get stuck because the velocity will be constantly bumping them towards the wall.
     
    CaptainBern likes this.
  5. Offline

    CaptainBern Retired Staff

Thread Status:
Not open for further replies.

Share This Page