How to set-up SetVelocity to send a player 3 blocks

Discussion in 'Plugin Development' started by electrobricks, Jun 14, 2013.

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

    electrobricks

    So hello there! I am trying to get a player to be sent 3 blocks and I have no idea to do this. From what I've seen around this area, Vectors is the way to go. So do you have a solution, a link to another thread(I searched but couldn't find anything), or maybe a link to somewhere else thats had this done before.

    Thanks,
    Electrobricks
     
  2. Offline

    chasechocolate

    3 blocks... Up? That would be on the Y axis, so player.setVelocity(new Vector(0, 0.30, 0)). You're gonna have to play around with those numbers (note that altering the center number will change how high the player is launched) until you get what you want.
     
  3. Offline

    electrobricks

    chasechocolate Oops forgot to mention to where the player is looking on the x or z axis. So how would you do that?
     
  4. Offline

    chasechocolate

    electrobricks try playing around with it:
    Code:java
    1. Location loc = player.getLocation();
    2. Vector direction = loc.getDirection();
    3.  
    4. direction.multiply(1.5); //To make them get launched farther (or not as far)
    5. direction.setY(0.5); //So they won't get shot into the ground
    6. player.setVelocity(direction);
     
  5. Offline

    MrTwiggy

    Code:java
    1. // This will get the direction vector on the X & Z axis
    2. // that the player is looking at.
    3. Vector direction = player.getLocation().getDirection();
    4. direction.setY(0);
    5. direction.normalize();
    6.  
    7. // Now, here's where it gets tricky.
    8. // If you want to teleport them, do this
    9. //-----------------------
    10. // Extend the direction vector by the number of blocks you want
    11. // to travel the player.
    12. direction.multiply(3);
    13.  
    14. player.teleport(player.getLocation().add(direction));
    15.  
    16. //---------------------------
    17. // However, if you want to set their velocity so that it will
    18. // throw them 3 blocks, you'll have to do more complex checks
    19. // to see the kind of block they are standing on, then look at NMS
    20. // to see the values of friction and then create a formula that will
    21. // set the correct velocity...I'm not gonna do that though.
     
Thread Status:
Not open for further replies.

Share This Page