Entities facing xz coordinates only (1.15.2)

Solution 1:

Method #1: Correction. First teleport according to your command, then in the same tick change the rotation back to horizontal with this command:

/data modify entity @e[type=armor_stand,limit=1] Rotation[1] set value 0f

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 and at every one of your rotating armour stands:

execute at @p run summon armor_stand ~ ~ ~ {Tags:["temp"],Marker:1,Invisible:1,NoAI:1,NoGravity:1,Invulnerable:1}
data modify entity @e[type=armor_stand,tag=temp,limit=1] Pos[1] set from entity @s Pos[1]
tp @s ~ ~ ~ facing entity @e[type=armor_stand,tag=temp,limit=1]
kill @e[type=armor_stand,tag=temp]

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.

Solution 2:

If I understand what you're both trying to accomplish in this Q&A, you can now (in JE 1.16.5) do this in one tidy command using execute, facing, and relative coordinates. I've taken the liberty of naming my armor stand "creepy" on account of it staring all the time.

/execute as @e[name=creepy, type=armor_stand] at @s facing entity @p eyes run tp @s ~ ~ ~ ~ 0