Minecraft wiki entry for execute, associated text: Sets the execution rotation; can match an entity's rotation
Syntax
rotated <rot> -> execute
rotated as <targets> -> execute
Arguments
<rot>: rotation (<yaw> <pitch>)
Must be a rotation with double number elements, including yaw and pitch, measured in degrees.
For the horizontal rotation (yaw), -180.0 for due north, -90.0 for due east, 0.0 for due south, 90.0 for due west, to 179.9 for just west of due north, before wrapping back around to -180.0.
For the vertical rotation (pitch), -90.0 for straight up to 90.0 for straight down.
Tilde notation can be used to specify a rotation relative to the executor's rotation.
<targets>: entity
Target entity/entities to match rotation with
Must be a player name, a target selector or a UUID.
Result
Unparseable if the argument is not specified correctly
Terminates if <targets> fails to resolve to one or more valid entities (named players must be online).
When multiple entities are selected, next sub-command is executed once in each execution rotation.
Example
Move every sheep 1 block in the direction that the player closest to it is facing: execute as @e[type=sheep] at @sORpositioned as @s rotated as @p run tp @s ^ ^ ^1