Players personal Pets

Discussion in 'Spigot Plugin Development' started by Preodym, Jun 10, 2016.

  1. Hey,

    I have an animal plugin and would like to have the pet always on the right side of the player. The animal is also teleported. However, always in the player. How can I teleport the animal on the right side next to the player?

    Code (Text):
        public void onMove(PlayerMoveEvent e) {
  2. I've started a thread about ArmorStands at the right side of the player a time ago, maybe you can read that first.
  3. Try getting the block next to the player as location.
  4. You could teleport them to the players direction and then choose the direction to the right of that.

    Here is what my mind is thinking... probably not the best idea but anyway.

    So X goes North and South
    And Z goes East and West

    When the player is facing North, add one block to the Z variable.
    Facing south, subtract the Z.
    Facing West, add one to X.
    Facing East, subtract one from X.
  5. That's not good, with this method, the mob isn't always at the right side of the player.
    Like @Kloudy said on this thread ( you need to use Vectors to calculate the Location. This is the code that he mention for an Armorstand:
    Code (Text):
    Vector playerLookDirection = player.getLocation().getDirection();

    //create a vector perpendicular to the look direction so that it updates position as the yaw changes
    Vector perpVector = new Vector(-playerLookDirection.getZ(), playerLookDirection.getY(), playerLookDirection.getX()).normalize();

    //use this vector to place the armorstand to the right of the player
    double x = player.getLocation().getX() + (perpVector.getX() * 1.5);//The 1.5 just places it 1.5-ish blocks away
    double y = player.getLocation().getY();
    double z = player.getLocation().getZ() + (perpVector.getZ() * 1.5);
    Location armorStandLocation = new Location(world, x, y, z);//use this location to place your ArmorStand
    You'll have to be sure and recalculate this armorStandLocation every time the player moves and update your ArmorStand's location with the newly calculated location.
    • Like Like x 1
    • Agree Agree x 1
  6. Worth a try at least. This looks like it might work better anyway.
  7. Yeah, sure, he can test also the yours. The mine will work maybe better but he need to understand the code.