#Make entity rotate to player direction

1 messages · Page 1 of 1 (latest)

nova fractal
#

i made a code where I did for when a player looks at an armor stand another armor stand on top rotating around it, the problem is that, from the moment the armor stand appears it doesn't rotate in the player's position, unless that you move too close to her

i made a code where I did for when a player looks at an armor stand another armor stand on top rotating around it, the problem is that, from the moment the armor stand appears it doesn't rotate in the player's position, unless that you move too close to her

https://paste.md-5.net/ibemicakuz.java

nova fractal
pure dune
#

Can you post your code?

nova fractal
#
// this part is IMPORTANT this make the armor stand rotate to player perspective direction

    private void makeLook(ArmorStand armor, Player player) {
        Location loc = player.getLocation();
        Location eloc = armor.getLocation();
        loc.setY(0);
        eloc.setY(0);

        Vector dif = loc.subtract(eloc).toVector();
        armor.teleport(armor.getLocation().setDirection(dif));
    }
    
// method to show the armor stand hologram
    
    public void showInfo(final Player player) {
        final Location eye = player.getEyeLocation();
        final Vector dir = eye.getDirection();
        final RayTraceResult rayTrace = new RayTraceResult(eye, dir.multiply(10));
        if (rayTrace.entities().size() < 1) {
            if (looking.get(player) == null) return;
            looking.remove(player);
            holograms.get(player).remove();
            holograms.remove(player);
            return;
        }
        final Entity entity = rayTrace.entities().get(0);
        if (!(entity instanceof ArmorStand)) return;
        if (looking.get(player) == entity) {
            final ArmorStand hologram = holograms.get(player);
            makeLook(hologram, player);
            return;
        }
        if (!(entity instanceof ArmorStand && entity.getName().contains("delete:"))) return;
        looking.put(player, entity);
        final String name = entity.getCustomName();
        final String[] str = name.split("delete:");
        ItemStack stack = null;
        stack = this.getLootName(str[1]).get().item();
        final Material type = stack.getType();
        final ArmorStand hologram = spawnHologram((ArmorStand) entity, type);
        makeLook(hologram, player);
        holograms.put(player, hologram);
    }```