Solved How to generate a random vector

Discussion in 'Plugin Development' started by Deleted user, Jul 1, 2014.

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

    Deleted user

    Code:java
    1. Item drop = World.dropItem(Location, ItemStack);
    2. drop.setVelocity(Vector);

    How can I generate some random vectors to launch items with random directions?
     
  2. Joiner Vectors are simply three numbers. Generate those numbers, and make a vector from them.
     
  3. Offline

    MineCrashKoen

    I think dropItemNaturally() gives it a random velocity, not sure though.

    Hope it helps :)
     
  4. Offline

    Deleted user

    Range?
     
  5. Offline

    THEREDBARON24

    Code:java
    1. Vector direction = new Vector();
    2. direction.setX(0.0D + Math.random() - Math.random());
    3. direction.setY(Math.random());
    4. direction.setZ(0.0D + Math.random() - Math.random());

    This is what I use. Seems to work well. Make sure to add - Math.random() to the y component of this if you want it to have the possibility of going in a downward facing direction.
     
    Orange Tabby likes this.
  6. Offline

    Deleted user

    It seems to drop without speed.

    How can I change speed (distance between spawn location and drop location)?

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

    fireblast709

  8. Offline

    qlimax5000

    I use:
    Code:java
    1. Vector v = Vector.getRandom(); // This makes a random vector but it doesn't shoot all ways //
    2. v.setX(v.getX() - 0.5f);
    3. v.setZ(v.getZ() - 0.5f); // Now it does //
    4. drop.setVelocity(v);
     
  9. Offline

    Deleted user

  10. Offline

    THEREDBARON24

    Glad I could help.
     
Thread Status:
Not open for further replies.

Share This Page