How do I get some other entity to rotate as me?

execute at @p run tp @e[tag=entity] ~ ~ ~ ~ 0 rotates an entity but it teleports it to me. Is there any way to just rotate an entity to look in the same direction without teleporting them?


Solution 1:

Assuming you are in the latest version(1.16.5), the following methods should work. For a single entity(excluding players), you could do:

data modify entity <selector with limit=1> Rotation set from entity <selector with limit=1> Rotation

It is very important to add limit=1 in the command. For use with multiple entities(excluding players), do the following.

execute as <selector for the entity you want to rotate> run data modify entity @s Rotation set from entity <selector with limit=1> Rotation

It is important to add limit=1 to the selectors where I said to. For use with players and entities, you need the tp command, you can do the following.

execute as <selector for the entity you want to rotate> at @s rotated as <selector with limit=1> run tp @s ~ ~ ~ ~ ~