Put entity on player smoothly

Discussion in 'Spigot Plugin Development' started by Big_Bad_E, Jan 7, 2020.

  1. So lets say that I have an armor stand with an item on its head.

    What I want to do is move it smoothly with the player. So the player walks forwards, the hat does too.

    If I just set the armorstand to have the same location, pitch, yaw, etc... the hat lags behind.
    The only solution I came up with is to make the armorstand ride the player.
    This has two big problems:
    1. The armorstand uses the player's yaw/pitch, not their head's yaw/pitch.
    2. The hat is floating way above the player.

    The item will be modeled, so if it needs to be re-positioned it can, but it is not ideal.

    I have no idea how I would go about doing this, I'm guessing that the riding entity is updated client side not just server side so it doesnt lag behind, so idk if I can change the position/rotation of the armorstand

    Thanks for any help, sorry this is mostly just asking how and not a code problem.
     
  2. You can teleport the armor stand every tick, but it may lag behind when the server lags. Put it in a repeating scheduler and just teleport it to the players location with the offset you desire.

    (Repeating schedule:
    Code (Java):
    int startDelay = 0; //ticks
    int repeatDelay = 1; //ticks

    Bukkit.getScheduler().scheduleSyncRepeatingTask(() -> {
        // code
    }, startDelay, repeatDelay);
    This is the only way to do it without having it ride them. You can teleport them with packets or with the bukkit API.
     
    #2 Nowaha, Feb 4, 2020
    Last edited: Feb 4, 2020
  3. I believe teleporting the ArmorStand to the player only works every 2-3 ticks. Try to use the Method inside CraftArmorStand (I forgot which one, but there’s one that should make it move fairly smoothly)
     
    • Creative Creative x 1
  4. it definitely works every tick
     
    • Agree Agree x 1
  5. I've personally tried this before

    Set the armorstand's gravity to 0 and make it teleport to the player on move. This saves the need to do it on tick. This isn't as seamless as riding when you're lagging (and blocks your screen when you're walking backwar, but it can rotate properly.

    Remember to set the armour stand to be a marker (armorstand.setMarker(true);), because if you don't the player can't interact with anything because the stand is "blocking" the player.