Solved Launch a snowball at the look direction of a player

Discussion in 'Plugin Development' started by 4thegame3, Nov 3, 2015.

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

    4thegame3

    Hello. I'm trying to spawn a snowball and to give it a velocity.
    I can't use the method player.launchprojectile for reasons that i wont explain here.
    So i decided to use world.spawnEntity method.
    Now i just need to give it a velocity in the direction the player is looking at.
    Code:
    Location loc = start.getLocation();
    World w = start.getWorld();
    Projectile proj = w.spawn(loc.add(0,1.5D,0),Snowball.class);
    proj.setVelocity(/*help*/)
     
  2. Offline

    Assist

    @4thegame3
    Have you tried looking at the methods in Location class? There's one that does exactly what you're asking.
     
  3. Offline

    4thegame3

    Yea sure, thanks for the spoonfeeding mr mistery.
    Solved by myself, for anyone who needs the code here it is.
    Code:
    Vector v = start.getLocation().getDirection();
            Location loc = start.getLocation().add(v.clone().multiply(2));
            World w = start.getWorld();
            Projectile proj = w.spawn(loc.add(0,1.5D,0), Snowball.class);
            System.out.println(start.getLocation().getPitch() +" "+start.getLocation().getYaw());
            Vector vec = new Vector(0,0,1);
            VectorUtils.rotateAroundAxisX(vec, (start.getLocation().getPitch()) * MathUtils.degreesToRadians);
            VectorUtils.rotateAroundAxisY(vec, -start.getLocation().getYaw() * MathUtils.degreesToRadians);
            proj.setVelocity(vec);
    I used the 2 libraries from open source library EffectLib. (MathUtils and VectorUtils)
     
Thread Status:
Not open for further replies.

Share This Page