I want to rotate an armor stand wherever I am located. And I can do that through this command:
execute as @e[type=armor_stand] at @s run tp @s ~ ~ ~ facing entity @p
But I want it to face my XZ coordinates only. I don't want its line of sight (the blue line in hitboxes) pointing directly at me when I'm flying. Any idea how?
Best Answer
Method #1: Correction. First teleport according to your command, then in the same tick change the rotation back to horizontal with this command:
This might have the side effect that the armour stand is occasionally visible looking up or down for one frame, but it did not ever happen when I tried it. It might be different on a laggy server.
Method #2: Dummy entity. Have a dummy entity that is always at the player's X and Z coordinate, but at the armour stand's Y coordinate and let the armour stand look at that instead.
To be absolutely sure that you always target the correct player, you need a function. Execute this function
as
andat
every one of your rotating armour stands:The downside of this system is obviously that it's more complicated and that it requires access to the server files, for putting the datapack into the folder. There are certain configurations of player and armour stand positions in which you cannot perfectly select the correct position to look at, at least not for all in one tick, unless you use a function.