[Easy] the "for" loop

Discussion in 'Plugin Development' started by ASHninja1997, Sep 6, 2013.

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

    ASHninja1997

    So basically i want to shoot a object 10 times at the same time. The problem is, that it shoots one snowball, that or it just shoots 10 in one cluster. If you see ANY problems in it please tell me so I can correct it. Thank you for your time and Knowledge.
    Code:java
    1. Vector v = p.getLocation().getDirection().normalize().multiply(0.5);
    2. Random random = new Random();
    3. v.add(new Vector(random.nextDouble(), random.nextDouble(), random.nextDouble()));
    4. for(int i = 0; i < 10; i ++)
    5. {
    6. Entity arrow = p.launchProjectile(Snowball.class);
    7. arrow.setVelocity(v);
    8. e.setProjectile(arrow);
    9. }
     
  2. Offline

    hapm

    first you need to copy the Vector v and than you need to randomize it in each iteration of the for loop. At the moment you randomize the vector at the start and than use the same v for each snowball you shoot, resulting in 10 snowballs looking like 1 as they all have the same velocity at the same start point at the same time
     
  3. Offline

    ASHninja1997

    hapm
    Very smart observation.
     
Thread Status:
Not open for further replies.

Share This Page