Snowball shotgun Math problems

Discussion in 'Plugin Development' started by frogawesome, Mar 23, 2014.

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

    frogawesome

    I'm trying to experiment with guns a little bit and wanted to make a shotgun, i'm having trouble with trying to dispearse the snowballs in the beginning. this is what i have atm:
    Code:
    for(int i = 0; i < 24; i++){
    Snowball snowball = p.launchProjectile(Snowball.class);
    float x = (float) -0.5 + (float) (Math.random() * ((0.4 - -0.4) + 0.3));
    float y = (float) -1.0 + (float) (Math.random() * ((0.8 - -0.5) + 0.4));
    float z = (float) -0.5 + (float) (Math.random() * ((0.4 - -0.3) + 0.3));
    Vector dir = p.getLocation().getDirection();
    snowball.setVelocity(dir.multiply(new Vector(snowball.getVelocity().getX()+x, snowball.getVelocity().getY()+y, snowball.getVelocity().getZ()+z)).normalize());
    }
    
     
  2. Offline

    frogawesome

    Still need help with this so bumping it
     
  3. Offline

    Garris0n

    So what's wrong?
     
  4. Offline

    frogawesome

    they are basicly all in eachother and i want them spreaded out, like a shotgun should do.
     
  5. Offline

    Garris0n

    Try removing the multiply and just using the vector.
     
  6. Offline

    frogawesome

    So basicly like this?

    Code:
    [FONT=Consolas]for(int i = 0; i < 24; i++){
    Snowball snowball = p.launchProjectile(Snowball.class);
    
    Vector dir = p.getLocation().getDirection();
    snowball.setVelocity(dir.multiply().normalize());
    }[/FONT]
    
    If so, that wouldn't really work because it does the same thing with the vector (but worse), they are all inside 1 line.
     
  7. Offline

    Zach_1919

    Garris0n likes this.
  8. Offline

    Garris0n

    No, now you're just not applying anything to the snowballs. You have to make the modifications to the x/y/z values of the original vector and then fire it, whether it be via .add() or via creating a new vector.
     
  9. Offline

    frogawesome

    Ahh, now I get it, I'll try that tomorrow
     
Thread Status:
Not open for further replies.

Share This Page