Attempting to make armor stand move where the player is looking.

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

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

    360_

    So basically I'm trying to create a cars plugin. I'm having issues making the armor stand move in the direction of which the player is looking. I've tried using vectors but it won't work since the armor stand has gravity false and it will stay in place. As of now, this is how it looks like https://imgur.com/EDzFStw . All I need help with is trying to get the armor stand to move at the same speed in the direction a player is looking. Hope someone can help me
    Code:
    Code:
    @EventHandler
            public void onPlayerInteract(PlayerInteractEvent e) {
                Player p = e.getPlayer();
                Balance bal = Balance.getInstance();
                if ((e.getAction() == Action.RIGHT_CLICK_AIR) && (p.getItemInHand().getType() == Material.RED_SANDSTONE)) {
                    ArmorStand armor1 = (ArmorStand) p.getWorld().spawnEntity(p.getLocation().add(0, -0.95, 0), EntityType.ARMOR_STAND);
                    ItemStack skull = new ItemStack(Material.SPONGE, 1);
                    armor1.setHelmet(skull);
                    armor1.setCustomName("§a" + p.getName() + " car");
                    armor1.setCustomNameVisible(true);
                    armor1.setGravity(false);
                    armor1.setPassenger(p);
                  
                  
                    new BukkitRunnable() {
                        @Override
                        public void run() {
                            if (p == null || !p.isOnline()) {
                                cancel();
                                return;
                            }
                           //stuff
                        }
                    }.runTaskTimer(this, 1, 2);
                }
            }
     
  2. Offline

    360_

    bump
     
  3. Offline

    DutchJellyV2

    Code:
    ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(p.getLocation().add(0, -0.95, 0), EntityType.ARMOR_STAND);
    stand.setVelocity(player.getVelocity());
    Won't that do the trick?
     
  4. Offline

    360_

  5. Offline

    Nostos

    @360_ here is a method that might work:
    Code:
    ArmorStand stand = (ArmorStand) player.getWorld().spawnEntity(player.getLocation(), EntityType.ARMOR_STAND);
                 
                    stand.getLocation().setPitch(player.getLocation().getPitch());
                    stand.getLocation().setYaw(player.getLocation().getYaw());
    
    that should make the armorstand look in your players eye direction if this doesn't work dm me for my SUPER SECRET NMS woo seriously though if you need any more help just tag me :D
    Edit: btw probably want to use the pitch and yaw thing in a PlayerMoveEvent
     
    Last edited: Mar 10, 2018
Thread Status:
Not open for further replies.

Share This Page