生成一个盔甲架后 朝向是固定的
尝试了armorStand.getEyeLocation().set
并没有什么 用 有大佬能提供个思路吗
尝试了armorStand.getEyeLocation().set
并没有什么 用 有大佬能提供个思路吗
创建一个location,设置它的pitch和yaw,再把盔甲加tp过去
这是我一个项目的源码
复制代码
- //修改盔甲架面向实体
- private void changeDirectionTo(ArmorStand armorStand, Entity entity) {
- Vector direction = getVector(armorStand).subtract(getVector(entity)).normalize();
- double x = direction.getX();
- double y = direction.getY();
- double z = direction.getZ();
- Location changed = armorStand.getLocation().clone();
- changed.setYaw(180 - toDegree(Math.atan2(x, z)));
- changed.setPitch(90 - toDegree(Math.acos(y)));
- armorStand.teleport(changed);
- }
- private float toDegree(double angle) {
- return (float) Math.toDegrees(angle);
- }
- private Vector getVector(Entity entity) {
- if (entity instanceof Player)
- return ((Player) entity).getEyeLocation().toVector();
- else
- return entity.getLocation().toVector();
- }
不晓得 看不懂 就是过来过任务