Launching Projectiles

Discussion in 'Plugin Development' started by Deleted user, Jul 16, 2013.

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

    Deleted user

    Would someone mind explaining or showing a piece of example code in which I could launch a projectile from one location and have it fire towards the direction of an Entity?
     
  2. Offline

    creepers84

    To easily fire a projectile: player.launchprojectile(fireball.class);
     
  3. Offline

    Deleted user


    Ah, but I'm attempting to launch a projectile from a specific location, not from a player.
     
  4. Offline

    blablubbabc

    Code:java
    1. double speed = 2.0;
    2. Arrow arrow = (Arrow) startLocation.getWorld().spawnEntity(startLocation, EntityType.ARROW);
    3. Vector direction = targetEntity.getLocation().toVector().subtract(startLocation.toVector()).normalize();
    4. arrow.setVelocity(direction.multiply(speed));
     
  5. Offline

    creepers84

    Alright, Why not try specifying the block and launching the projectile from that. Then set the target of the projectile by specifying the projectile as something like Arrow arrow = (Code).

    =D You ninja XD

    Don't forget to specify the startlocation! =D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page