Velocity Help!!!

Discussion in 'Spigot Plugin Development' started by XZot1K, Jun 8, 2016.

  1. So i need to throw a player in the direction they are looking, but i also need to make sure i can throw them about 500 blocks away.

    I have tried this:
    Code (Text):
    p.setVelocity(e.getTo().getDirection().multiply(500));
     
  2. I dont think putting 500 in the multiplier will throw them 500 blocks away, but where does e.getTo come from? Just use p.getLocation().getDirection(). Because i dont think you can get direction of a block ^^
     
  3. Im using the onMove event its getting a player location. I need to throw them in the direction they are looking at but everytime i multiply over curtain number it goes the same distance.
     
  4. If you multiply it by 500 it will say they moved too fast in the console. To prevent that, try setting their walk speed to something high. Also, like said above, multiplying by 500 won't throw them 500 blocks away. If you want to do that, I recommend you create a repeating BukkitRunnable, run it every few ticks or so and check the distance from where they started. (Don't check the distance every tick though. It's bad on performance)
     
    • Winner Winner x 1
  5. Try this:

    Code (Text):
    public HashMap<String, Location> loc = new HashMap<String, Location>();  
        loc.put(p.getName(), p.getLocation());
            new BukkitRunnable() {

                @Override
                public void run() {
                    if (loc.get(p.getName()).distance(p.getLocation()) >= 500) {
                        cancel();
                    } else {
                        p.setVelocity(p.getLocation().getDirection().multiply(50));
                    }

                }

            }.runTaskTimer(getPlugin(), 0, 20 * 1);
     
  6. I need to throw them once instead of multiple times :/
     
  7. I wish minecraft didn't put limitations on player velocity so you could see for yourself why multiplying their velocity by 500 won't move them 500 blocks. :confused:
     
    • Agree Agree x 1
  8. oh yeah ive always know it doesn't thats what i had to test if there was a cap on the velocity.
     
    • Creative Creative x 1