Solved Launching a wither skull looks... weird?

Discussion in 'Plugin Development' started by CreeperShift, Apr 10, 2013.

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

    CreeperShift

    I'm trying to launch a witherskull with a bone, but it looks very choppy:



    Code:
    public void onShoot(PlayerInteractEvent e) {
            ItemStack hand = e.getPlayer().getItemInHand();
            if (hand != null && hand.getType() == Material.BONE) {
                if (e.getAction() == Action.RIGHT_CLICK_AIR) {
                    Location player_location = e.getPlayer().getLocation();
     
                    double pitch = ((player_location.getPitch() + 90) * Math.PI) / 180;
                    double yaw = ((player_location.getYaw() + 90) * Math.PI) / 180;
     
                    double x = Math.sin(pitch) * Math.cos(yaw);
                    double y = Math.sin(pitch) * Math.sin(yaw);
                    double z = Math.cos(pitch);
     
                    Vector vector = new Vector(x, z, y);
     
                    Entity ent = e
                            .getPlayer()
                            .getWorld()
                            .spawnEntity(
                                    e.getPlayer()
                                            .getLocation()
                                            .add(0, 1, 0)
                                            .add(e.getPlayer().getLocation()
                                                    .getDirection().normalize()),
                                    EntityType.WITHER_SKULL);
     
                    ent.setVelocity(vector.multiply(2.5D));
    As you can see from the video, for half a second the skull appears to be flying correctly, then appears to be really fast, glitches back and forth and hits much later than it seems. (As it would with the correct speed)
     
  2. Client prediction isn't that great in this game, consider lowering the speed.

    Or you could try player.launchProjectile()
     
  3. Offline

    TheUpdater

    Hope this helps
    Code:
                        WitherSkull WitherSkull = e.getPlayer().launchProjectile(WitherSkull.class);
                        WitherSkull.setShooter(e.getPlayer());
                        WitherSkull.setVelocity(e.getPlayer().getLocation().getDirection().multiply(1));
     
  4. Offline

    CreeperShift

    I tried to multiply it by 0.1, but the choppy stuff looks the same :(

    I'll try launchProjectile(), thanks! :)


    EDIT: yes launchProjectile() works flawless! :)
     
  5. Offline

    TheUpdater

    i posted this code try it
    Code:
                        WitherSkull WitherSkull = e.getPlayer().launchProjectile(WitherSkull.class);
                        WitherSkull.setShooter(e.getPlayer());
                        WitherSkull.setVelocity(e.getPlayer().getLocation().getDirection().multiply(1));
     
  6. Offline

    CreeperShift

    Didn't see this before but thanks, it looks similar to how I've done it!
     
Thread Status:
Not open for further replies.

Share This Page