Velocities/Vectors

Discussion in 'Plugin Development' started by TehVoyager, Oct 1, 2013.

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

    TehVoyager

    I'm making a kit plugin and am using a jump feature in one of them. I need to make the player jump upwards (Y) and go outwards the way they are looking, (F1, F2, F3, F4)
    So far this is my code:
    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEvent e){
    3. Player player = e.getPlayer();
    4. if(plugin.kit.containsKey(player.getName())){
    5. if(plugin.kit.containsValue(5)){
    6. if(e.getAction() == Action.RIGHT_CLICK_AIR|| e.getAction() == Action.RIGHT_CLICK_BLOCK){
    7. if(player.getItemInHand().getType() == Material.GHAST_TEAR){
    8. player.setVelocity(player.getLocation().getDirection().multiply(3).setY(player.getVelocity().getY() + 2));
    9. }
    10. }
    11. }
    12. }
    13. }


    The problem with that code is that if the direction is up it gets messed up :(

    anything?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  2. Offline

    TheEyeMonster

    Maybe because its angle is 360 and you can't have angle above 360.
     
  3. Offline

    TehVoyager

  4. Offline

    MrSnare

    Try
    Code:java
    1. Location loc = player.getTargetBlock(null, 2).getLocation();
    2. Location loc2 = player.getEyeLocation();
    3. Vector vec = new Vector((loc.getX() - loc2.getX()), loc.getY() - loc2.getY(), (loc.getZ() - loc2.getZ()));
    4. player.setVelocity(vec);
    5.  
     
  5. Offline

    TehVoyager

    MrSnare
    doesnt work any better ): You can just look at the air and spam it to fly

    I need this A.S.A.P any possible solutions, The problem is when you look up at the error it just make you fly.

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

    LazyLemons

    Only allow them to jump if they are on the ground.
     
    MrSnare likes this.
  7. Offline

    MrSnare

    I would have thought this is pretty obvious. Or only allow them to use it once every 5 seconds or something
     
  8. Offline

    TehVoyager

    k thanks :D, what about a double jump ?
     
  9. Offline

    MrSnare

    let them do it once, make them wait a short time(like 0.5 of a second) then let them do it again once more but not again for 5 seconds.
     
Thread Status:
Not open for further replies.

Share This Page