player.setVelocity() not launching player into Y-Direction

Discussion in 'Plugin Development' started by HellsMiner, Dec 21, 2013.

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

    HellsMiner

    Hey guys,
    I have a problem with a plugin wich should launch a player into the air (like the launchpads on theHive)

    Code:java
    1. player.setVelocity(new Vector(player.getLocation().getDirection().multiply(10).getX(), 5.0D, player.getLocation().getDirection().multiply(10).getZ()));

    this code doesn't work for me, it just pushes the player in the direction he is looking, not in the air.

    How can I get that the player is launched into the air too?

    Thanks, HellsMiner
     
  2. Offline

    ChronicNinjaz

    HellsMiner
    Why don't you try setting the velocity of Y then ? in your code your only setting X and Z ... jefn
     
    John00708 likes this.
  3. Offline

    Deleted user

    ChronicNinjaz HellsMiner
    ....
    It clearly says 5.0D

    Also, I've been experiencing issues with this too. Maybe bukkit broke for vectors?
     
  4. Offline

    HellsMiner

    //bump...
     
  5. Offline

    Developing

    HellsMiner This?
    Code:
    player.setVelocity(new Vector(0,64,0));
     
  6. Offline

    HellsMiner

    Developing
    This wont work too.

    Anyone who knows a different way to code this?

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

    hellboyPS

    We used this too in couple of our plugins and players were complaining about it. Must be a bukkit issue.
    Sure to get fixed soon. I don't think there is any proper substitute for it at the moment.
    Maybe you could do it with NMS code. Otherwise I would just wait for Bukkit to fix it and use player.teleport() for a temporary quick-fix on critical sections.
     
  8. Offline

    Brixishuge

    Try removing .getDirection(), since AFAIK, it's returning where player is looking...
     
  9. Offline

    AoH_Ruthless

    Uhh, that's because you are using .getDirection().

    If you want to launch them into the air AND in the direction they are facing, you can view the source for my plugin PlayerLauncher.
     
  10. Offline

    NathanWolf

    This is most certainly not broken.

    You are setting the X and Z velocity to be twice the Y velocity, which has to fight gravity. So that's probably not going to do much.

    That may be a little overkill, maybe try (0, 5, 0) to start with? Make sure to check the console for "player moved too quickly" warnings, which may be preventing the velocity change altogether.
     
  11. Offline

    HellsMiner

    NathanWolf
    I tried this but I get no "player moved too quickly" warnings and it doesn't shut up the player anyway :/

    I used this code:
    Code:java
    1. player.setVelocity(new Vector(0, 5, 0));
     
  12. Offline

    NathanWolf

    Hm, I guess maybe even 5 is too much? That doesn't sound right... But I guess just try reducing the speed until it stops hitting that warning.
     
  13. Offline

    Chinwe

    If you set the Y value of a vector to 1, that shoots them around 23 blocks into the air - 5 will most likely kick them for flying/trigger many NoCheatPlus warnings :eek:

    To shoot them forward and a bit up, you can simply do this:
    Code:
    Vector direction = player.getLocation().getDirection().multiply(4); // should be enough
    direction.setY(direction.getY() + 0.5); // small boost up
    player.setVector(direction); // chuck 'em
    
     
  14. Offline

    HellsMiner

    Chinwe
    Just tried this Code, but i just dont get it working :/ just boosts the Player a bit.

    Bump

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

    TeddyTheTeddy


    The code that Chinwe posted was perfect, but it shoots them up slightly because of the line of code that looks like:
    Code:java
    1. direction.setY(direction.getY() + 0.5); // small boost up

    if you need them to go higher change where it says 0.5 to what ever you want, but I wouldn't suggest more than 5.
     
  16. Offline

    HellsMiner

    TeddyTheTeddy
    But it doesnt work! It just doesnt shoot the Player in the air. Just gives him a little boost forward.
     
  17. Offline

    HellsMiner

    Downgrading to 1.6.4 its just working fine :O Anything to do different with this in 1.7.2?
     
  18. Offline

    NathanWolf

    That's pretty weird. I haven't noticed any differences myself, my favorite spell is basically this (set player velocity in the direction you're pointing) and I've been running 1.7 since the first dev build... I wish I had some more insight for you, sorry :(
     
  19. Offline

    HellsMiner

    Is something wrong with my Bukkit version? Wich version are you using where this is working?
     
  20. Offline

    DeMaggo

    I tried that. I know the solution. Bukkitservers don't allow such fast upwards movement. Try it with a value between 1 and 3 and there you go.
     
  21. Offline

    HellsMiner

    DeMaggo
    Values between 1 and 3 Do not work too.

    Bump

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

    Garris0n

    Are you using the latest build? Also, bump once per 24 hours.
     
  23. Offline

    HellsMiner

    Garris0n
    Yes I'm using the latest build.
     
  24. Offline

    HellsMiner

  25. Offline

    bigteddy98

    How hard can this be...
    Code:java
    1. p.setVelocity(new Vector(0, 1, 0).multiply(1D));

    Set the velocity higher to shoot up harder.
     
  26. Offline

    Garris0n

    I did stuff with velocities yesterday and did not have this issue. Is this the only plugin on your server? Can you post the full code you're using?
     
  27. Offline

    ShearsSheep

    Are you sure that it does not work for 1.7.2 , Here is my Code,

    Code:java
    1. e.getPlayer().setVelocity(e.getPlayer().getLocation().getDirection().multiply(4));
    2. e.getPlayer().setVelocity(new Vector(e.getPlayer().getVelocity().getX(), 1.0D, e.getPlayer().getVelocity().getZ()));

    I hope this do work , good luck :)
    -ShearsPig
     
  28. Offline

    HellsMiner

    ShearsSheep
    I'm sure its a 1.7 problem, in 1.6 the same code is working well. Already tried a few different 1.7 bukkit versions but everytime the same problem.
    Other plugins that are using similar code doesnt work for me too.
     
  29. Offline

    ShearsSheep

    :/ Its working for me..
     
  30. Offline

    Captain Dory

    HellsMiner
    The problem you're having is probably you're not registering events, not extending JavaPlugin, implementing Listener etc. If it works for other people, it's not the code they gave you that's not working.
    Post your entire code, and i'll see what I can do.
     
Thread Status:
Not open for further replies.

Share This Page