Помогите Как реализовать полёт стрелы

  • Автор темы Автор темы swat1x
  • Дата начала Дата начала

swat1x

Активный участник
Пользователь
Баллы
76
Имя в Minecraft
swat1x
Хочу сделать стрелу, которую в каком бы направлении не выстрелить, она бы летела за ближайшим игроком. На словах всё просто: "Энтити -> Энтити". Но где бы не искал, ничего про настройку полёта стрелы нету. Мб тут кто поможет. (При этом не любую стрелу, а особую, которую через команду выдавать или типо того)
 
Примерно так, код хрень но суть понятна
PHP:
public class Homing extends JavaPlugin implements Listener {
    public static Homing instance;
    public List<Projectile> arrows;
   
    public void onEnable() {
        instance = this;
        arrows = new ArrayList<Projectile>();
        Bukkit.getPluginManager().registerEvents(this, this);
        Bukkit.getScheduler().runTaskTimer(instance, () -> {
            arrows.forEach(arr -> {
                arr.getLocation().getWorld()
                    .spawnParticle(Particle.HEART,
                        arr.getLocation(),
                        1);
                List<Player> near = arr.getNearbyEntities(10, 10, 10)
                    .stream().filter(entity -> entity instanceof Player)
                    .map(entity -> (Player) entity)
                    .filter(entity -> {
                        Player shooter = (Player) arr.getShooter();
                        return shooter.getDisplayName() != entity.getDisplayName();
                    }).collect(Collectors.toList());
                if(near.size() < 1) return;
               
                Vector vec = getDifferentialVector(
                    arr.getLocation(), near.get(0).getLocation()
                ).normalize();
                arr.setVelocity(vec.multiply(1.5));
            });
        }, 0, 1);
    }
   
    @EventHandler
    public void onShoot(ProjectileLaunchEvent e) {
        arrows.add(e.getEntity());
    }
   
    @EventHandler
    public void onHit(ProjectileHitEvent e) {
        arrows.remove(e.getEntity());
    }
   
    public static Vector getDifferentialVector(Location from, Location to) {
        return new Vector((to.getX() - from.getX()), to.getY() - from.getY(), (to.getZ() - from.getZ()));
    }
}
 
Код:
public Vector findPath(Location from, Location to) {
        double dX = from.getX() - to.getX();
        double dY = from.getY() - to.getY();
        double dZ = from.getZ() - to.getZ();
        double yaw = Math.atan2(dZ, dX);
        double pitch = Math.atan2(Math.sqrt(dZ * dZ + dX * dX), dY) + Math.PI;
        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);
        return vector;
    }
 
Назад
Верх