How to get player's position and not direction where the player is facing at? I am using this code below and it checks if position is same as before, but it also checks which direction the player is facing :/ PHP: $this->position = $this->player->getPosition();if($this->player->getPosition()->equals($this->position)){
Are you trying to get the player's position with Level without their YAW and Pitch or with the YAW and Pitch?
Uh, no it doesn't? Yaw and pitch are not included in any math classes, only entity classes. Here is the line where equals is called, and as you can see, it doesn't check yaw and pitch. https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/math/Vector3.php#L226
You don't get it, try executing that code yourself in a delayed task. Turn around and you'll see that equals() doesn't return true anymore. For some reason turning around changes the position of a player.
Update 1: Yaw and pitch are included in a level based class, but the equals function is still not overridden. Checking more in-depth. https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/level/Location.php Update 2: getPosition() and getLocation() are two different functions and shouldn't have any involvement in one another(except that Location is an extension of Position, it shouldn't work the other way around) https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/entity/Entity.php#L1231
That's not the point. Changing the way you look seems to change your position. This doesn't have to do with checking pitch and yaw, it has to do with rotation causing position changes!
Ah, I gotcha. Ok, I understand the issue now. I have a couple of theories, but let me double check to be on the safe side.
It's an issue. I have created a pull request regarding this issue. Player::getLocation() includes yaw and pitch. If the pull request gets merged, your code would be PHP: $this->location = $this->player->getLocation();if($this->player->getLocation()->equals($this->location)){}
This is still not the issue Look at the comments above and the title. Rotating more than a certain amount seems to CHANGE position of the player which makes the equals() check return false. This doesn't have to do with a function from the PMMP API, it has to do with something in the core/MCPE changing the position when changing yaw.
Works fine for me, this is what I used. Of course, yaw and pitch should be lesser than 361. PHP: $player->setRotation(yaw, pitch);
Omg Do we really need a wall of text to explain this issue? It isn't that complicated... Here's exactly what is meant with this issue. I'm guessing @BruhLol is trying to make a plugin with a delayed teleport to a position. I was working on the exact same thing with the rewrite of EssentialsPE, and encountered the EXACT same issue. When scheduling the task and checking if the position was same to the position the moment the task was scheduled, this usually works. Say the position of the player the moment the task got scheduled is $originalPosition, and the player object is $player. First I schedule the task, which looks exactly like this below. PHP: <?phpnamespace EssentialsPE\Tasks;use EssentialsPE\Loader;use pocketmine\level\Position;use pocketmine\Player;use pocketmine\utils\TextFormat;class DelayedTeleportTask extends BaseTask { private $player; private $originalPosition; private $teleportPosition; public function __construct(Loader $loader, Player $player, Position $originalPosition, Position $teleportPosition) { parent::__construct($loader); $this->player = &$player; $this->originalPosition = $originalPosition; $this->teleportPosition = $teleportPosition; } public function onRun($currentTick) { if($this->player->isOnline()) { if($this->player->getPosition()->equals($this->originalPosition)) { $this->player->teleport($this->teleportPosition); } else { $this->player->sendMessage($this->getLoader()->getConfigurableData()->getMessagesContainer()->getMessage("general.teleport-cancel")); $this->player->teleport($this->player); } } }} Ignore the things that don't matter, only the equals check matters for now. If the player has stood still the whole time, the equals check returns true. Of course. Moving your face to a certain point doesn't matter either, but if you turn around enough the equals check suddenly returns false. So, if the task gets scheduled when I look south and I turn around and face north, your position changes. Don't ask me why, but it does. It does not have to do ANYTHING with the API methods. If this isn't clear enough, I give up.
Why &$player? Try if($player->getPosition()->floor()->equals($originalPos->floor())){}(or Vector3::round()) It might be something to do with the decimals.
Quote="Ignore the things that don't matter" That was a typo Anyways, I don't think position should change when turning around and not actually moving. I find it really weird.
@dktapps Okay got some results. Sometimes it does have the same position, sometimes it doesn't. Result 1: Spoiler Code: [12:55:09] [Server thread/INFO]: [Sandertv: Teleported Sandertv to 737.43, 138, 1067.78] object(pocketmine\level\Position)#14264 (4) { ["level"]=> object(pocketmine\level\Level)#9504 (0) { } ["x"]=> float(737.4343) ["y"]=> float(71) ["z"]=> float(1067.7787) } object(pocketmine\level\Position)#13016 (4) { ["level"]=> object(pocketmine\level\Level)#9504 (0) { } ["x"]=> float(737.4118) ["y"]=> float(71) ["z"]=> float(1067.8118) } As you can see, that attempt immediately reproduced the issue. I simply looked about 90 degrees yaw away and it got cancelled. Attempt 2: Spoiler Code: [12:55:35] [Server thread/INFO]: [Sandertv: Teleported Sandertv to 737.41, 141, 1067.81] object(pocketmine\level\Position)#11759 (4) { ["level"]=> object(pocketmine\level\Level)#9504 (0) { } ["x"]=> float(737.4118) ["y"]=> float(71) ["z"]=> float(1067.8118) } object(pocketmine\level\Position)#13142 (4) { ["level"]=> object(pocketmine\level\Level)#9504 (0) { } ["x"]=> float(737.4118) ["y"]=> float(71) ["z"]=> float(1067.8118) } In this attempt it worked fine even though I turned around 180 degrees (yaw) I made a couple more of these tests and most resulted in the numbers not being equal after turning around. With the code I posted above you can easily reproduce this by spinning around in spot after the task gets scheduled. Blame me for doing ctrl+c in the terminal because I wanted to copy paste. (LOL) That's why I don't have more var_dumps here.