Solved Shoot fireball specific direction

Discussion in 'Spigot Help' started by QuadroRTX8000, Jun 23, 2022 at 1:38 PM.

  1. I can't find any helpful information on vectors, so I would like info on vectors and how to use them to say, shoot a fireball straight down or to positive x and z.
     
  2. In games, vectors are mutable objects defining a position or a direction in 3D space.

    They can be composed of floats / doubles / integers, but the data type must be same in all of the vectors values:
    X,
    Y,
    Z


    Bez názvu.png

    So, if you use a vector(x:1, y:0, z:0) as a direction for the fireball:
    Code (Java):
        @EventHandler
        public void onPlayerCLick(PlayerInteractEvent interactEvent) {
            Player player = interactEvent.getPlayer();
       
            Vector vector = new Vector(1, 0, 0);
            Fireball fireball = player.getWorld().spawn(player.getLocation().setDirection(vector), Fireball.class);
        }
    It will shoot the fireball to that direction unrelatively to the player;

    View attachment 709454

    If you want to shoot the fireball to direction the player is looking use:

    Code (Text):
        @EventHandler
        public void onPlayerCLick(PlayerInteractEvent interactEvent) {
            Player player = interactEvent.getPlayer();

            Fireball fireball = player.getWorld().spawn(player.getLocation(), Fireball.class);
        }
     

    Attached Files:

    #2 LukeC0de, Jun 23, 2022 at 3:02 PM
    Last edited: Jun 23, 2022 at 3:12 PM
    • Informative Informative x 1
  3. Thank you, this is the EXACT information I needed.
     
  4. I hate begging, but could you please rate it, bec i spent a while on it :D
     
  5. Sorry for late response, but this is a great response. Not only does it give you the info on how it works and how to use it, but you also show some real world examples and code. 10/10.