Solved Making a Player Jump

Discussion in 'Plugin Development' started by KeybordPiano459, Nov 20, 2012.

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

    KeybordPiano459

    I need to make a player jump five blocks in the air, and I can't get player.setVelocity() to work, is there a different way to do it?
     
  2. Offline

    javoris767

    Did you add new Vector?
    Code:java
    1. target.setVelocity(new Vector(0.0, 2.5, 0.0));
     
  3. Offline

    KeybordPiano459

    javoris767
    I've tried that but it launches me some 50 blocks in the air, not like two.
     
  4. Offline

    javoris767

    Hmm, does happen to low decimals too :confused:
     
  5. Offline

    KeybordPiano459

    Well when I set the 'y' to 1 it made me jump 4 blocks -_- I'll figure it out from here :p

    Hey, I was wondering- can I set the velocity of a player, but make it so that the player goes backwards? I want to use .getDirection(), but I can't figure out how to get the reverse direction of a player.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  6. Offline

    RealDope

    Well getDirection() returns an array of I believe just the pitch and yaw (might also include the x,y,z but I doubt it). Just reverse the pitch and that would be his direction flipped around.

    Also you'll have to call:
    Location loc = player.getLocation();
    loc.getDirection();

    Since getDirection is a location thing not player.
     
  7. Offline

    md_5

    Thats because the velocity starts at 1, and then you keep rising each time, a little bit less until it starts going negative and you fall. The peak of your jump is 4 blocks.
     
  8. Offline

    KeybordPiano459

    Oh...

    RealDope
    How do I reverse the pitch?
     
  9. Offline

    RealDope

    Meant to say yaw, since yaw is left to right.

    Not totally sure, this stuff isn't my strong suit. Google it, figure out how yaw is stored.
     
  10. Offline

    KeybordPiano459

    I've tried to Google it, and haven't been able to find anything on reversing the direction that a player is looking in, does anyone else know anything about this?
     
  11. Offline

    RealDope

    Mess around with it.

    Teleport a player to (0, 0,0 0, 1);

    X, Y, Z, pitch = 0
    Yaw = 1

    See how it works
     
  12. Offline

    Drkmaster83

    Wouldn't that disallow movement and mess up the yaw?
     
  13. Offline

    RealDope

    No clue, like I said I don't know how pitch / yaw works.

    When using regular teleporting (usually storing a players location and saving it then teleporting to it later), there are no problems with that stuff right? This should be pretty much the same
     
  14. Offline

    KeybordPiano459

    It would do what Drkmaster83 said, I'm pretty sure. Also, if the player is facing one way, depending on what way they're facing, the player could go forwards, backwards, or any other direction.
     
  15. Offline

    RealDope

    Try something like this:

    Code:JAVA
    1.  
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    3. Player player = (Player) sender;
    4. if(cmd.getName().equalsIgnoreCase("jump") {
    5. player.sendMessage("Yaw: " + player.getLocation().getYaw);
    6. player.sendMessage("Pitch: " + player.getLocation().getPitch);
    7. }
    8. return true;
    9.  


    See how the Yaw and Pitch are stored. Then try something like this:
    Code:JAVA
    1.  
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    3. Player player = (Player) sender;
    4. if(cmd.getName().equalsIgnoreCase("jump") {
    5. World world = player.getLocation().getWorld();
    6. double x = player.getLocation().getX()
    7. double y = player.getLocation().getY();
    8. double z = player.getLocation().getZ();
    9. float pitch = player.getLocation().getPitch();
    10. float yaw = player.getLocation().getYaw();
    11. float newYaw = yaw / 2;
    12. Location newLoc = new Location(world, x, y, z, pitch, newYaw);
    13. player.teleport(newLoc);
    14. }
    15. return true;
    16. }
    17.  


    100% untested, no clue if it'll work or not, just something off the top of my head.
     
  16. Offline

    KeybordPiano459

    RealDope
    Just looking at it I'm pretty sure this wont work. If you're trying to use yaw/2, what if the players yaw was at 2? It would be set to one, and the player wouldn't even notice a difference. Also, I want the player to jump back, not be teleported. =/
     
  17. Offline

    nisovin

    Try something like this:

    Code:
    Vector v = player.getLocation().getDirection().multiply(-1).setY(1);
    player.setVelocity(v);
    
     
    KeybordPiano459 likes this.
  18. Offline

    KeybordPiano459

    This looks promising :) I'll test it when I get home

    nisovin
    Thanks! The code worked =D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
Thread Status:
Not open for further replies.

Share This Page