strange problem with velocitys

Discussion in 'Plugin Development' started by xize, Dec 31, 2014.

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


    Hey hey,

    so Im trying to make some sort of tennis feature in my plugin however for some reason setting a new Velocity fails but I don't understand why.

    first I spawn the chicken with this given velocity, this snippet is psuodo since I know where the problem lays but I don't understand why it doesn't change the velocity again in my next snippet:

    Location loc = justsomelocation;
    Chicken chicken = (Chicken) loc.getWorld().spawnEntity(loc, EntityType.CHICKEN);
    chicken.setCustomName(ChatColor.GOLD + "tennis ball");
    chicken.setVelocity(new Vector(0,0,0).normalize()); //makes it so the chicken stays on the same location this works fine.
    now in my event when a player tries to damage the chicken I want to give the chicken the velocity of the direction of the player I do it like this:

    public void onDamage(EntityDamageByEntityEvent e) {
         if(e.getEntity() instanceof Chicken) {
              Chicken chicken = (Chicken)e.getEntity();
              if(chicken.getCustomName().equalsIgnoreCase(ChatColor.GOLD + "tennis ball")) {
                    if(e.getDamager() instanceof Player) {
                          Player p = (Player) e.getDamager();
                          p.sendMessage(ChatColor.GRAY + "poof!"); //works fine, so the event works.
                          chicken.setVelocity(p.getLocation().getDirection().multiply(2).normalize()); //in theory I think the chicken should move to the direction the player is looking at *2 but it still seem to appear to use the 0,0,0 vector but how?
    ive commented the code where it fails or what is fine, I just dont understand why it does stay on 0,0,0 even when I set it.

    thanks for the help :)
Thread Status:
Not open for further replies.

Share This Page