Solved Help with Euler Angles and Armor Stands

Discussion in 'Plugin Development' started by apbritt98, Sep 7, 2015.

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

    apbritt98

    So basically what I'm trying to do is when an entity is spawned, an armor stand with it's head in the same direction as the entity will spawn in as well.

    This is what I've got so far, beware I don't know much about 3D Vectors and Euler Angles.


    Code:
    //Convert yaw and pitch to radians
                double yaw = (double)(entity.getLocation().getYaw());
                yaw = Math.toRadians(yaw);
                double pitch = (double)(entity.getLocation().getPitch());
                yaw = Math.toRadians(pitch);
              
              
                EulerAngle a = new EulerAngle(pitch,yaw,0);
                stand.setHeadPose(a);
    
     
  2. Offline

    Zombie_Striker

  3. Offline

    apbritt98

  4. Offline

    Zombie_Striker

    @apbritt98
    Found out why
    This is good, you're getting the radious of the yaw, and then setting the yaw
    This is bad, this is getting the pitch,and then setting the yaw again

    Remember, copy and pasting is not Java's friend.
     
    apbritt98 likes this.
  5. Offline

    apbritt98

    @Zombie_Striker
    Haha, just realized that right before I saw your post, thanks for that. but I'm still having a problem. I made a new test plugin that spawns in an armorstand and updates its head to the direction your head is facing, but there is a problem. The armor stands only display correctly when I'm facing south, and if the armor stand is facing any other direction then the positioning is off.

    Here is what I've got:
    Code:
        @Override
        public void onEnable(){    
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                public void run() {
                    double x=0,y=0,z=0;
                    x = Math.toRadians(p.getLocation().getPitch());
                    y = Math.toRadians(p.getLocation().getYaw());
                    EulerAngle a = new EulerAngle(x,y,z);
                    s.setHeadPose(a);
                }
            }, 0, 1);
        }
    
        @Override
        public void onDisable(){
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            if(sender instanceof Player){
                p = (Player) sender;
                s = (ArmorStand)p.getWorld().spawnEntity(p.getLocation(), EntityType.ARMOR_STAND);
                s.setHelmet(new ItemStack(Material.JACK_O_LANTERN));
            }
            return true;
        }
    }
    
    Is there anyway I can spawn the stand in facing south?

    EDIT:
    Fixed it by setting the stand's yaw to 0 when it is spawned.
     
    Last edited: Sep 7, 2015
Thread Status:
Not open for further replies.

Share This Page