Targeting frozen players with wither skulls

Discussion in 'Plugin Development' started by deleted_90940145, Mar 6, 2015.

Thread Status:
Not open for further replies.
  1. Hey,

    I want to target players, which can not move with wither skulls, I've posted some threads on other forums, but the answers were not useful.

    Current code:
    Code:
    for(Entity entity : w.getEntities()){
                            if (entity instanceof Wither){
                                if(entity.getUniqueId().toString().equals(bossentity)){
                                   
                                    Vector v = player.getLocation().subtract(entity.getLocation()).toVector().normalize();
                                   
                                    WitherSkull ws = ((ProjectileSource) entity).launchProjectile(WitherSkull.class);
                                    ws.setCharged(true);
                                    ws.setVelocity(v);
             }
         }
    }
    The issue with this code is that the wither skull is kinda going opposite my direction.

    Video:
    That's a video I've posted on another forum, which is why it's kinda old, but doesn't matter.

    Appreciate any help.
     
  2. Offline

    Hex_27

    @driver-e I'm not an expert at this, but if you run out of ideas, you could try this. First, spawn an invisible and invulnerable entity riding the wither. Preferably a zombie. Then you can get the place the zombie is looking at.
    Code:
    Location zombieloc = zombie.getLocation().add(0,1,0);
                     double pitch = ((zombieloc.getPitch() + 90) * Math.PI) / 180;
                        double yaw  = ((zombieloc.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);
                      
                        String dir = getCardinalDirection(zombie);
                         Location loc = zombieloc;
                        //use java 1.7 for this. If you can't then use elseif instead of switch
                        switch(dir){
                       
                        //may cause you to go inside blocks
                       
                        case "N" : loc = new Location(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ() - 1, loc.getYaw(), loc.getPitch()); break;
                        case "NE": loc = new Location(loc.getWorld(), loc.getX() + 1, loc.getY(), loc.getZ() - 1, loc.getYaw(), loc.getPitch()); break;
                        case "E" : loc = new Location(loc.getWorld(), loc.getX() + 1, loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); break;
                        case "SE" : loc = new Location(loc.getWorld(), loc.getX() + 1, loc.getY(), loc.getZ() + 1, loc.getYaw(), loc.getPitch()); break;
                        case "S" : loc = new Location(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ() + 1, loc.getYaw(), loc.getPitch()); break;
                        case "SW" : loc = new Location(loc.getWorld(), loc.getX() - 1, loc.getY(), loc.getZ() + 1, loc.getYaw(), loc.getPitch()); break;
                        case "W" : loc = new Location(loc.getWorld(), loc.getX() - 1, loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); break;
                        case "NW" : loc = new Location(loc.getWorld(), loc.getX() - 1, loc.getY(), loc.getZ() - 1, loc.getYaw(), loc.getPitch()); break;
                   
                        }
                     
                      WitherSkull a = event.getPlayer().getWorld().spawn(loc, WitherSkull.class);
    This is the getCardinalLocation()
    Code:
        public static String getCardinalDirection(Entity e) {
            double rotation = (e.getLocation().getYaw() - 90) % 360;
            if (rotation < 0) {
            rotation += 360.0;
            }
            if (0 <= rotation && rotation < 22.5) {
            return "N";
            } else if (22.5 <= rotation && rotation < 67.5) {
            return "NE";
            } else if (67.5 <= rotation && rotation < 112.5) {
            return "E";
            } else if (112.5 <= rotation && rotation < 157.5) {
            return "SE";
            } else if (157.5 <= rotation && rotation < 202.5) {
            return "S";
            } else if (202.5 <= rotation && rotation < 247.5) {
            return "SW";
            } else if (247.5 <= rotation && rotation < 292.5) {
            return "W";
            } else if (292.5 <= rotation && rotation < 337.5) {
            return "NW";
            } else if (337.5 <= rotation && rotation < 360.0) {
            return "N";
            } else {
            return null;
            }
            }
    This way, you can set a repeated task such that a skull will fire at the player, when the zombie looks at the player. When the zombie's wither host dies, you can kill the zombie.
     
  3. Hmm, well the thing is that I'm building a system which shoots at all players around the wither at once, and mobs aren't so quick in tracking, not sure if this would help, but thank you very much for your response.
     
  4. Offline

    Hex_27

    @driver-e It works well for single players. That's all I can say.
     
  5. Offline

    Avygeil

    @driver-e Your code seems fine.. This might be an inherent problem with skulls. It seems like they aim at you and then turn somewhere else. They don't really go to the opposite direction though, and sometimes they go to the same spot. Is there an entity they could target behind the walls?

    You could debug to make sure it's not a problem with the vector : try setting the velocity every tick instead. Tell me if the head follows you after that, it would mean the problem is somewhere else, and I have an idea for a workaround if that's the case. :) (skulls have tons of problems, like being invisible with no shooter attribute).
     
  6. I'd like to know the workaround, this is a flat map, and entity spawning is off, so there's no other entities in this map.
     
Thread Status:
Not open for further replies.

Share This Page