Velocity and Vectors

Discussion in 'Plugin Development' started by BurnerDiamond, Jan 26, 2015.

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

    BurnerDiamond

    I'm current making a KitPVP plugin and I was wondering if it's possible to do multiple things.

    1. Setting a player y vector to 3 while keeping the velocity of him running the same.

    2. Get the location of where he lands after he is shot up and then damaging near players in the radius of 4.

    3. Shoot the players up at a certain velocity depending by the players distance from the block hit?
     
  2. Offline

    CraftCreeper6

    @BurnerDiamond
    A lot of Vectors. Essentially, you would need to use the .setVelocity() method in the player class.
    1. Player#setVelocity(Vector vector);
    2. Player#getNearbyEntities(int, int, int);
    3. Same as one except check for the highest block in the players current position and use the .distance(); method to check the blocks. Use Player#setVelocity(Vector vector);
     
  3. Offline

    BurnerDiamond

    @CraftCreeper6

    For the first question I want to keep the players running speed as usual. So that it keeps going straight but the y vector also goes up.
     
  4. Offline

    SuperOriginal

  5. Offline

    BurnerDiamond

    @SuperOriginal

    But wouldn't I have to get the velocity before I change the y velocity?
     
  6. Offline

    CraftCreeper6

  7. Offline

    BurnerDiamond

    @CraftCreeper6

    What I meant was when you run, you have a set velocity. What I want to do is set the velocity of the way you're running and keep it the same as a running velocity. I want the y to be 3 and the speed velocity to go in the direction he's looking in.
     
  8. Offline

    Hoolean Retired Staff

    @BurnerDiamond

    Just adjusting the y-value of the player's velocity Vector should retain the player's running angle and velocity, so I can't say I fully understand what you're saying. Alternatively, if you are suggesting that you also want the player to be launched in the direction they are looking, then you want to look into player.getLocation().getDirection(). :)
     
  9. Offline

    coasterman10

    You may want to look up the mathematical definition of a vector and study it for a bit, it will help you greatly with understanding how to use the Bukkit vector as it is 99% true to the mathematical definition.

    As for launching the player, you want to create a vector that points upwards to launch the player. If you want their looking direction to have an influence on this, you can also add some multiple of their looking direction vector (as Hoolean suggested above). Then, add this vector to their velocity, and set their velocity to the result.

    As for knocking back the players who take damage, find where ground-zero is and subtract the player's location from that. Normalize this vector and you will have the direction, then just multiply by whatever amount they should be knocked back. You can also add a bit of a Y component to this to launch them up a bit.
     
    Hoolean likes this.
Thread Status:
Not open for further replies.

Share This Page