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

    xize

    also I don't know that much about velocities but shouldn't you use .normalize() behind the vector what you set?
    I guess that should stop being kicked I geuss but I can be wrong.
     
  2. Offline

    XgXXSnipz

  3. Offline

    HellsMiner

    Captain Dory

    All Listeners are registered and it "works". (Only pushes the Player forwarad a bit, but not launching him into the Sky :D)
    Code:java
    1. @EventHandler
    2. public void onStep(PlayerInteractEvent e){
    3. if(e.getAction().equals(Action.PHYSICAL)){
    4. Player p = e.getPlayer();
    5. if(e.getClickedBlock().getType() == Material.STONE_PLATE){
    6. Block b = e.getClickedBlock().getLocation().subtract(0.0D, 1.0D, 0.0D).getBlock();
    7. if(b.getType() == Material.COAL_BLOCK){
    8. p.setVelocity(p.getLocation().getDirection().multiply(4));
    9. p.setVelocity(new Vector(p.getVelocity().getX(), 2.5D, p.getVelocity().getZ()));
    10. }
    11. }
    12. }
    13. }
     
  4. Offline

    Timbals

    I have this problem too
    I solved it by teleporting the player 0.3 blocks up before setting the veloctiy
    That works pretty good but not perfectly
     
  5. Offline

    Deleted user

    Timbals
    :O Is that what you do?

    I've found velocities and vectors to be broken, but I can never figure out why it works on double jump, but not on a launch pad
     
  6. You need to teleport the player up a bit.
    Code:java
    1. p.teleport(p.getLocation().add(0, 0.5, 0));
    2. p.setVelocity(new Vector(p.getLocation().getDirection().getX(),p.getLocation().getDirection().getY()+2,p.getLocation().getDirection().getZ()));
     
    BDKing88 likes this.
  7. Offline

    gentlemon

    well guys, had to struggle with this issue alot lately.
    simple and most comfortable solution is to delay the velocity setting by 1 tick.
    Teleportation works fine too, but it looks a little crappy.

    Code:java
    1. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    2.  
    3. public void run() {
    4. player.setVelocity(vec);
    5.  
    6. }
    7. }, 1L);
     
Thread Status:
Not open for further replies.

Share This Page