Solved Teleport player a few blocks ahead

Discussion in 'Plugin Development' started by ocomobock, Sep 1, 2013.

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

    ocomobock

    I'm trying to figure out how to teleport the player maybe 3 blocks in the direction they're looking. I haven't done much with this kind of thing.

    Could someone show me how to do this?
     
  2. ocomobock
    Try this
    Code:java
    1. public Location getFront(Player user, int range) {
    2. Location loc = user.getEyeLocation();
    3. Vector direction = loc.getDirection().normalize();
    4.  
    5. for (int i = 0; i <= range; i++) {
    6. loc.add(direction).getBlock();
    7. }
    8.  
    9. return loc;
    10. }

    Usage:
    Code:java
    1. somePlayer.teleport(getFront(somePlayer, 2));

    Untested.
     
  3. Offline

    ocomobock

    Assist

    Thanks, that worked exactly how I wanted it to.
     
Thread Status:
Not open for further replies.

Share This Page