Teleport a player to face an entity?

Solution 1:

The new syntax for /teleport in 1.13 added a "facing entity" option.

/execute as @p positioned as @s run teleport @s ~ ~ ~ facing entity ENTITY_TO_FACE

Solution 2:

Here's an alternate solution to the other answer. It should work more accurately without thousands of command blocks, although it relies a lot more on trickery rather than a kind of brute-force method.

When you summon the Target mob that you want to face towards, you need to give it a specific UUID so that the UUID isn't chosen at random. I'll use an ArmorStand for this example:

/summon ArmorStand ~ ~1 ~ {CustomName:"Target",UUID:1-2-3-4-5}

If you're wanting to face towards a naturally spawned mob (where the UUID will be random), you'll need to summon another entity on top of it with a specific UUID as shown above.

Near to this Target, summon some kind of mob that can be aggressive, but also give it slowness and anti-jump boost. I'm using a Witch for this, although they throw potions which you may need to /kill. You can also make this Aggressor invisible if you don't want players to notice it.

  /execute @e[name=Target] ~1.5 ~ ~ /summon Witch ~ ~ ~ {AbsorptionAmount:350000000000000000000000000000000000000.0f, CustomName:Aggressor,CustomNameVisible:1,Attributes:[{Name:"generic.knockbackResistance",Base:1f},{Name:"generic.movementSpeed",Base:0f}],ActiveEffects:[{Id:8,Amplifier:-127,Duration:2147483647}]}

(The huge absorption amount is to make this Aggressor invincible, but still able to take damage)

Now you'll want to make the Aggressor angry at the Target. This is the reason we needed the Target to have a UUID that we know, we're going to summon a snowball that pretends it has been thrown by the Target above the Aggressor:

/execute @e[name=Aggressor] ~ ~ ~ /summon Snowball ~ ~2.1 ~ {ownerName:"1-2-3-4-5"}

The snowball falls onto the Aggressor, and it thinks the Target threw it (ArmorStands don't even have arms, but mobs are dumb) and starts tracking the Target.

At this point you should have whatever mob you're using looking very angry at an ArmorStand.

Now that the setup is done, it's fairly easy to use, even repeatedly.

Teleport the Aggressor to the player:

/tp @e[name=Aggressor] @p

Then wait a moment as the Agressor reorientates to face the target, and then teleport the player to the Aggressor:

/tp @p @e[name=Aggressor]