Solved how to teleport a player in the direction they are looking

Discussion in 'Plugin Development' started by King V, Jan 20, 2016.

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

    King V

    simple question :p how do i teleport someone in the direction they are looking in? as in if they are looking somewhere and i run a void that would teleport them 1 block in the direction they are looking in.

    so far:
    Player player = event.getPlayer();
    Location loc = player.getLocation();
    float yaw = loc.getYaw();
    float pitch = loc.getPitch();
    Location loc1 = player.getLocation();
    player.teleport(loc1);
     
  2. Offline

    ShowbizLocket61

    @King V
    Conveniently, there's a getDirection() method which returns an unit vector representing your direction. Unit means the magnitude is one, which is what you're looking for.

    Code:
    Player player = event.getPlayer();
    Location loc = player.getLocation();
    Vector dir = loc.getDirection();
    loc.add(dir);
    player.teleport(loc);
     
  3. Offline

    WolfMage1

    please. don't. spoon. feed.
     
  4. Offline

    ShowbizLocket61

    @WolfMage1
    I shared that code to benefit him, not harm him. It's easy to understand. I also provided a text explanation. Please don't salt.
     
    Nandi_ likes this.
  5. Offline

    WolfMage1

    Just don't make a habit of giving people code, instead just tell them what to do.
     
    ShowbizLocket61 likes this.
  6. Offline

    ShowbizLocket61

    @WolfMage1
    Will do. And shall we stop spamming this thread with forum ethics?
     
  7. Offline

    King V

    thanks for the help :p works!
     
Thread Status:
Not open for further replies.

Share This Page