1

If I have an entity, is it possible to teleport that player to face the entity without teleporting the player to the entity (Just changing his rotation)? How could I accomplish this?

2

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
1

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]
0

You can do it with armor stands.

When a player teleports to an armor stand, they take the rotation of the armor stand. Here is what you do:

  1. Summon an armor stand 1 block south of the entity, facing north.
  2. Teleport the player to that armor stand.
  3. Kill the armor stand.

It will be useful to name the armor stand so you can find it later without interfering with other armor stands.

EDIT: How to do it without moving the player

You'll need a lot of command blocks, one for each little arc of the circle. The more you have, the more accurate it will be.

Here are the steps:

  1. Create an armor stand exactly where the player is.
  2. Based on where the entity is relative to the player, rotate the armor stand to face the entity. This is the part that requires a lot of command blocks. For example, if the player is 1 block south and 1 block east of the entity, the armor stand should rotate to 135º. You then divide the area surrounding the entity into a grid, then make a command block for each square. The command block makes the armor stands face the right way based on which grid square it is (you calculate the correct rotations beforehand). The grid squares can be larger than 1 block by 1 block.
  3. Teleport the player to the armor stand. It's at the same place as the player, but rotating the right way, so the player will rotate.

You need to use the armor stands because you can't edit a player's entity data.

I think SethBling did a video with this type of thing once. I can't find it right now, but I think it was about a nether portal that showed you the nether on the other side. There was another video about endermen that always face you that might help.

  • Great answer, but is it possible to do it without teleporting the player to the creeper, just changing his rotation? – user112881 May 25 '15 at 21:02
  • It'll take more command blocks, but you can. I'll update my answer. – FlyingPiMonster May 25 '15 at 21:21
  • "Based on where the entity is relative to the player, rotate the armor stand to face the entity." I think you should expand on how this part is accomplished, considering this step is pretty much what OP is asking how to do. Could you give an example command? – SirBenet May 26 '15 at 0:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy