Entity Firing

Discussion in 'Plugin Development' started by ZingCraft, Oct 25, 2014.

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

    ZingCraft

    Hello all,

    I am developing a plugin that will shoot a wither skull from a location to a location using vector subtraction (code below). The wither skull fires fine and goes to the right location. However, it launches it super quick and thus makes the wither skull invisible. Is there any way to fix this?

    Code:java
    1. Location p = getRandomPlayer().getLocation();
    2.  
    3. Vector from = new Vector(wither1ss.getX(), wither1ss.getY(), wither1ss.getZ());
    4. Vector to = new Vector(p.getX(), p.getY(), p.getZ());
    5.  
    6. Vector vector = to.subtract(from);
    7.  
    8. WitherSkull wither1Skull = (WitherSkull) wither1ss.getWorld().spawnEntity(wither1ss, EntityType.WITHER_SKULL);
    9. wither1Skull.setDirection(vector.normalize());
    10. wither1Skull.setVelocity(vector);
     
  2. Offline

    Avygeil

    ZingCraft
    Code:java
    1. wither1Skull.setVelocity(vector.normalize().multiply(x));

    Adjust x to get your perfect speed. :)
     
  3. Offline

    ZingCraft


    When I do that, I see the witherskull for the first fraction of a second, then it goes invisible again. I have tried multiplying the velocity by 0.1, 2 and 10. I can see that it takes longer for the witherskull to explode when it hits me, but it is still invisible (going too fast)
     
  4. Offline

    mythbusterma

    ZingCraft

    That seems to be incorrect, as doing Vector#normalize() creates a new vector with the total magnitude equal to 1, in the corresponding direction. So doing Vector#normalize().multiply(2) and setting the velocity to that vector would result in the wither skull flying at (almost) exactly 2 m/s, perhaps you should look elsewhere for what is causing the problem.
     
  5. Offline

    ZingCraft

    mythbusterma

    I did once try removing the setVelocity line (commenting out) and the same thing occurred. Could it perhaps be related to the setDirection?
     
  6. Offline

    Avygeil

    ZingCraft

    Sounds like a client side issue. I've heard about a similar bug when summoning skulls with command blocks. It might be related to the fact that the skull has no owner. As a test, you could try to multiply vector by -1 (so that it launches from the player), and instead of using World#spawnEntity, use player.launchProjectile(WitherSkull.class), and keep the velocity/direction code. If it works, then I guess something hacky would be to spawn an entity at the "from" location and then kill it right after...
     
Thread Status:
Not open for further replies.

Share This Page