Solved Making armor stand rotate

Discussion in 'Plugin Development' started by 360_, Mar 22, 2018.

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

    360_

    So I'm trying to make my "balloon" rotate slowly instead of looking the direction I'm looking at (this is how it looks like atm)
    picture (open)
    works fine now

    and here is the code
     
    Last edited: Mar 27, 2018
  2. Offline

    Zombie_Striker

    By getting the player's location, you area also getting their yaw and pitch. If you want to slow the change, set the yaw and pitch to be some average of the two values every time the runnable is called.
     
  3. Offline

    360_

    @Zombie_Striker I tried playing around with that and seeing that i get but i don't think I'm doing it correctly
     
  4. Offline

    Zombie_Striker

    @360_
    What have you tried? Can you post your code?
     
  5. Offline

    360_

    @Zombie_Striker I tried this
    Code:
     @EventHandler
            public void onPlayerInteract(PlayerInteractEvent e) {
                Player p = e.getPlayer();
                if ((e.getAction() == Action.RIGHT_CLICK_AIR) && (p.getItemInHand().getType() == Material.PRISMARINE_SHARD)) {
                    Location loc = p.getLocation();
                    ArmorStand armorStand = (ArmorStand) p.getWorld().spawnEntity(p.getLocation().add(0, 2.5, 0), EntityType.ARMOR_STAND);
                    Chicken rab = (Chicken) p.getWorld().spawnEntity(p.getLocation().add(0, 2.5, 0), EntityType.CHICKEN);
                    ItemStack skull = new ItemStack(Material.TNT, 1);
                        armorStand.setHelmet(skull);
                        armorStand.setVisible(false);
                        armorStand.setGravity(false);
                        armorStand.setBasePlate(false);
                        rab.setLeashHolder(p);
                        armorStand.getEquipment().setHelmet(skull);
                        rab.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY,70000, 2));
                        p.sendMessage("§7Toggled balloon");
                        //Animation
                        new BukkitRunnable() {
                            @Override
                            public void run() {
                                if (p == null || !p.isOnline()) {
                                    cancel();
                                    return;
                                }
                                rab.teleport(p.getLocation().add(0 , 3.0, 0));
                               armorStand.teleport(p.getLocation().add(0 , 2.3, 0));
                               armorStand.getLocation().setPitch(2);
                               armorStand.getLocation().setYaw(2);
                            }
                        }.runTaskTimer(this, 1, 1);
                }
            }
     
  6. Offline

    Zombie_Striker

    1. Setting the yaw and pitch does not actually change the yaw and pitch. These setters need to be done on the location instance that you are teleporting the armrostand to. That means you need to create an instance of the player's location, set the yaw and pitch for that location, and then teleport the armorstand using that location instance.
    2. You're setting the yaw and pitch to a constant (2), so it will never change. Try creating an average like below to change the speed:
    Code:java
    1. float yaw = 0;
    2. yaw += p.getLocation().getYaw();
    3. //Add the player's yaw.
    4. yaw += armorStand.getLocation().getYaw();
    5. //Add the armorstand's yaw MULTIPLIED by 9,
    6. //This means the existing yaw will be HEAVILY FAVORED, so the transition will be slow
    7.  
    8. yaw /= 10;
    9. //Dividing it by the amount of entries added, creating an average.
    10.  
    11. /**
    12. *Then do the same for Pitch, set the yaw and a pitch for the location, and then teleport the AS to that location
    13. */
    14.  
     
  7. Offline

    360_

    Last edited: Mar 27, 2018
Thread Status:
Not open for further replies.

Share This Page