Set Projectile Direction

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

  1. Offline


    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

    @EventHandlerpublic void onClick(PlayerInteractEvent event){
    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. @GHOSTDJ Try this:
    1. meteor.setVelocity(block.getLocation().toVector().subtract(meteor.getLocation().toVector()).normalize().multiply(2));

Share This Page