[Tutorial] Make bow shoot the opposite direction

Discussion in 'Resources' started by Developing, Dec 14, 2013.

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

    Developing

    Just playing around with things. Thought i would share this cool piece of reference code.
    Code:java
    1. @EventHandler
    2. public void onEntityBow(EntityShootBowEvent e){
    3.  
    4. if(e.getEntity() instanceof Player){
    5. Player p = (Player) e.getEntity();
    6. Float speed = e.getForce();
    7. Arrow arrow = (Arrow) e.getProjectile();
    8. Vector vec = p.getLocation().getDirection();
    9. arrow.setVelocity(new Vector
    10. (vec.getX() * speed * -1,
    11. vec.getY() * speed * -1,
    12. vec.getZ() * speed * -1));
    13. }
    14. }
     
    ArthurMaker likes this.
  2. Offline

    BungeeTheCookie

    Developing Would this spawn an arrow directly infront of the player and then since it is going backwards, hit the player?
     
  3. Offline

    Developing

    BungeeTheCookie Nope. The arrow basically goes the opposite direction you are facing after you release the bow. Wouldn't hit you at all in any case.
     
  4. Offline

    BungeeTheCookie

    This is an awesome resource. I will use this sometime :)
     
  5. Offline

    Developing

  6. Offline

    Developing

  7. Offline

    wouterrr

    Why should you use this?
     
  8. Offline

    Jozeth

    To fire backwards without looking behind?
     
  9. Offline

    malandrix_bunny

    wouterrr
    You could use this to look forward, and if you know somethings behind you, shoot backwards.
     
  10. Offline

    Developing

    wouterrr Other than those above mentioned , you can use this to prank someone.
     
    Jozeth likes this.
  11. Offline

    Garris0n

    Why are you bumping it? This is resources, there's no reason to bump it...
     
    glen3b, Rainy37, jimuskin and 2 others like this.
  12. Offline

    Ivan

    Code:java
    1. @EventHandler
    2. public void BowShoot(EntityShootBowEvent event){
    3. if(event.getEntity() instanceof Player)
    4. event.getProjectile().setVelocity(event.getProjectile().getVelocity().multiply(-1));
    5. }
     
  13. Offline

    Plo124

    Making the y velocity a negative means if you fire with a slight upwards direction, it will fire downwards, so I would leave the y velocity how it is, and only reverse the x and z.
     
  14. Offline

    Ivan

    You guys do realize this just makes the arrow hit the shooter itself...? xD
     
  15. Offline

    Phasesaber


    Wow. Look at the first post.
     
  16. Offline

    Garris0n

    Wow. Look at the date.
     
    glen3b, Jhtzb, DSH105 and 2 others like this.
  17. Offline

    Phasesaber

    Oops, didn't see it. :p
     
Thread Status:
Not open for further replies.

Share This Page