1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Rotating head seems to change position

Discussion in 'Development' started by BruhLol, May 19, 2017.

  1. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    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)){
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Are you trying to get the player's position with Level without their YAW and Pitch or with the YAW and Pitch?
     
  3. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    This seems to be a core issue or an MCPE issue. I can confirm this. I've had the exact same issue.
     
    BruhLol likes this.
  4. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
  5. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    Just $player->getPosition(); with level i guess
     
  6. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    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.
     
    BruhLol likes this.
  7. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    EXACTLY THATSWHAT I AM DOING, DELAYEDTASK @Sandertv
     
    Sandertv likes this.
  8. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    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
     
    Last edited: May 19, 2017
    corytortoise likes this.
  9. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    Can you var_dump the position data of each position and post it here?
     
  10. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    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!
     
    jasonwynn10, falk and BruhLol like this.
  11. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    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.
     
    jasonwynn10, Sandertv and BruhLol like this.
  12. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    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)){
    }
     
    jasonwynn10 and BruhLol like this.
  13. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    This is still not the issue :p
    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.
     
  14. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Works fine for me, this is what I used. Of course, yaw and pitch should be lesser than 361.
    PHP:
    $player->setRotation(yawpitch);
     
    Last edited: May 20, 2017
  15. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Omg :facepalm:

    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:
    <?php

    namespace 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 $loaderPlayer $playerPosition $originalPositionPosition $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.
     
    jasonwynn10 and BruhLol like this.
  16. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Why &$player?
    Try
    if($player->getPosition()->floor()->equals($originalPos->floor())){}(or Vector3::round())
    It might be something to do with the decimals.
     
    Last edited: May 20, 2017
  17. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    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.
     
    jasonwynn10 likes this.
  18. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    Got any actual numbers to prove that theory @Sandertv?
     
  19. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    I can go ahead and get some var_dumps done. Give me a second.
     
    BruhLol likes this.
  20. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    @dktapps Okay got some results. Sometimes it does have the same position, sometimes it doesn't.

    Result 1:
    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:
    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.
     
    jasonwynn10 likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.