Setting the velocity of a fireball

Discussion in 'Plugin Development' started by Anonomoose, Jul 2, 2014.

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

    Anonomoose

    Hi all!

    I'm trying to set the velocity of a fireball after a player launches it, but I'm having some issues and I can't point out why it isn't working. Here's a snippit of the code:

    Code:java
    1. Fireball fireball = player.launchProjectile(Fireball.class);
    2. fireball.setVelocity(fireball.getVelocity().multiply(5));


    I'm pretty confused as to why this isn't working, the velocity doesn't change whatsoever after it being spawned. Any suggestions?

    Thanks a lot!
     
  2. Offline

    ZodiacTheories

    Anonomoose

    I think you need to add:

    Code:java
    1. fireball.setVelocity(new Vector(//fireball multiplication));
     
  3. Offline

    Anonomoose

    ZodiacTheories

    Thing is I need it to be a vector in the same direction of what the fireball's currently going in, just multiplied. I tried multiplying the direction instead, but nothing changed.
     
  4. Offline

    ZodiacTheories

    Anonomoose

    Do you want the fireball's x to multiply by 5, its y, its z or all of them?
     
  5. Offline

    Anonomoose

    Just the X and Y, I tried this:

    Code:java
    1. Fireball fireball = player.launchProjectile(Fireball.class);
    2. fireball.setShooter(player);
    3. Vector velocity = fireball.getVelocity();
    4. fireball.setVelocity(new Vector(velocity.getX() * 5, velocity.getY(), velocity.getZ() * 5));


    Same result of course..
     
  6. Offline

    ZodiacTheories

    Anonomoose

    Why the fireball.setShooter(player) - I am not expert but haven't you already done that in the line before?
    What happens when you try that? Any errors in console?

    Anonomoose

    Sorry for the double post, but also, why are you creating a new vector object when you created one on the line before?

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

    Anonomoose

    ZodiacTheories

    The set shooter thing was from before, I was spawning the fireball in as an entity and obviously had to set the shooter for that, then I decided just to use the launchProjectile method. Also I created a Vector object before that so I didn't have to keep on getting the velocity each time for the 3 components, nothing much really.
     
  8. Offline

    nelson2tm

    Just what i think you need, i use it to shoot mobs.
    Maybe this helps?
    Code:java
    1. chicken.setVelocity(loc.getDirection().multiply(5));

    Where the 5 is the velocity multiply. (Bad english? :oops:)
     
  9. Offline

    Anonomoose

    nelson2tm

    Tried that before, still doesn't work =/
     
  10. Offline

    Waffles87

    I had some trouble with fireball velocities too.. I'm not at home so I can't check my code until Monday (I'll get back to you) but for now try replacing:

    fireball.setVelocity(fireball.getVelocity().multiply(5));

    with:
    fireball.setDirection(fireball.getDirection().multiply(5));


    setDirection seems to also take a Vector argument, and the API has this comment:

    setDirection(Vector direction)
    Fireballs fly straight and do not take setVelocity(...) well.
     
  11. Offline

    Waffles87

    Hey again, so I tested this out and it works pretty well (on CB 1.7.9), except the fireball doesn't seem to fly perfectly straight. You can play around with how fast you actually want it - I tried 3.0 instead of 5.0 and it was still pretty fast.

    Fireball fireball = player.launchProjectile(Fireball.class);
    fireball.setShooter(player);
    Vector velocity = fireball.getDirection();
    fireball.setDirection(velocity.multiply(5.0));

    Hope this works out for you.
     
Thread Status:
Not open for further replies.

Share This Page