Is there a function to get back position of a player? I want a player to teleport behind a player where the player isnt facing, how can i do this?
What you could do is getting the direction vector of the player to teleport to, and subtract the vector you get from the position of the player to teleport to. PHP: $player->teleport($target->subtract($target->getDirectionVector())); You can multiply the direction vector should you want to teleport the player at a further distance behind the target player. Do note that if the target is facing downwards, the player will teleport above the target.
You can check the direction of the player and tp to the same coords but with the x or the z -1 or +1 of the players position
You may want to rotate the vector in case the player is facing the floor/sky. In this case, it is more appropriate to calculate a new vector using the target's yaw only. PHP: $yaw = $target->getYaw();$dx = sin(deg2rad($yaw));$dz = -cos(deg2rad($yaw));// sin(y) ** 2 + cos(y) ** 2 === 1, no need to normalize$player->teleport($target->add($dx, 0, $dz));