Minecraft – Teleporting behind player

minecraft-commandsminecraft-java-edition

How is it possible to teleport an armour stand behind a player (with its position updating as the player moves) in 1.15+?

Best Answer

You'll need to create a scoreboard tag for each player and armor stand pair to use this command.

/execute as @e[tag=stand1,type=minecraft:armor_stand] positioned as @a[tag=stand1] run teleport @s ~ ~1 ^-1 facing ^ ^ ^

This command should teleport an armor stand to the nearest player, one block above and one behind them.

Breakdown of command:
/execute as @e[tag=stand1,type=minecraft:armor_stand] - This will pick an armor stand with the scoreboard tag "stand1" and execute the command from it.
positioned as @p[tag=stand1] - Sets all the relative positions used with ~ and ^ to be relative to the player with the scoreboard tag "stand1".
run teleport @s ~ ~1 ^-1 - Teleports the armor stand to the player, up one block, and one block behind the direction the player is facing.
facing ^ ^ ^ - Causes the armor stand to face the same direction the player's head is.