Setting Entity Velocity

Discussion in 'Plugin Development' started by AndyMcB1, Aug 2, 2013.

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

    AndyMcB1

    How would I set the velocity of an entity (such as an arrow or an egg) to project based on where I am looking..

    I'd want the egg to be going semi fast..


    Cheers :)
     
  2. Code:java
    1. @EventHandler
    2. public void onShoot(ProjectileLaunchEvent event) {
    3. if(event.getEntity() instanceof Arrow) {
    4. Arrow arrow = (Arrow) event.getEntity();
    5. if(arrow.getShooter() instanceof Player) {
    6. Player shooter = (Player) arrow.getShooter();
    7. shooter.launchProjectile(Egg.class).setVelocity(arrow.getVelocity());
    8. }


    A bit confused but should work fine ;)
     
  3. Offline

    AndyMcB1

    How do i do that without the need to shoot an arrow?
     
  4. Code:java
    1. shooter.launchProjectile(Snowball.class).setVelocity(new Vector(1,1,1));

    You will need to create a vector, i don't know exactly what the numbers stand for but you can just try it out?!
     
  5. Offline

    AndyMcB1

    That's working, but not where I am looking at.
     
  6. Offline

    Ivan

    EmilMcDuck the numbers stand for the x y and z axis.

    EDIT: eg, if you would apply a vector 0 5 0 to a player, the player would be rocketed into the sky.
     
  7. You have to get the vector for your target block...
     
  8. Offline

    Ivan

    Wrong, you have to get the vector of the player, which can be achieved by checking his location.
     
  9. Ivan How would you do this?
     
  10. Offline

    Ivan

    Vector vector = player.getLocation().getDirection();
     
  11. I already tried this, but the snowball is as fast as it is in its normal case
     
  12. Offline

    MakerofRobots

    AndyMcB1
    sorry emil, tagged the wrong person :/

    give this a try:
    Code:java
    1. shooter.launchProjectile(WHATEVER.class).setVelocity(player.getLocation().getDirection().multiply(SOME FACTOR));
    2. //switch WHATEVER.class
    3. //SOME FACTOR should be 3 - 5ish
    4.  
     
Thread Status:
Not open for further replies.

Share This Page