Set Projectile Direction

Discussion in 'Plugin Development' started by GHOSTDJ, Nov 25, 2020.

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

    GHOSTDJ

    So I am making a plugin where the user has a sword and if he right clicks a block with it, a fireball spawns and comes down to the block that the player right-clicked on. I have figured out till the part to spawn the fireball 40 blocks above the right-clicked block but the fireball goes in a straight line instead of coming down. Can anyone please help me? Here is my code

    Code:
    @EventHandlerpublic void onClick(PlayerInteractEvent event){
    if(event.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.GOLDEN_SWORD))
    if(event.getPlayer().getInventory().getItemInMainHand().getItemMeta().hasLore()){
    Player player = (Player) event.getPlayer(); if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
    Block block = event.getClickedBlock();Location loc = block.getLocation().add(0,40,0);World world = player.getWorld();Entity meteor = world.spawn(loc, Fireball.class);meteor.setVelocity(block.getLocation().getDirection().multiply(2));}
    }
    }
     
  2. Offline

    KarimAKL

    @GHOSTDJ Try this:
    Code:Java
    1. meteor.setVelocity(block.getLocation().toVector().subtract(meteor.getLocation().toVector()).normalize().multiply(2));
     
Thread Status:
Not open for further replies.

Share This Page