Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Teleporting player with pitch

Comments in 'Plugin Development' started by WillotheBlessed, Aug 17, 2015.

  1. WillotheBlessed
    Offline

    WillotheBlessed Active Member

    Joined:
    Sep 17, 2014
    Posts:
    69
    Minecraft User:
    will
    It doesn't appear that teleporting the player with a set pitch is working. Yaw and Position seem fine, but pitch is always set to 0.
  2. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    The pitch is $sender->getName()->getLocation()->pitch
    Then, on the teleport function use teleport(x,y,z,yaw,pitch);
    Worked fine for me
    Last edited: Sep 1, 2015
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Please confirm before you post. $sender->getName(), assuming your $sender is a CommandSender, returns a string. You cannot call methods upon it.
    iksaku and thebigsmileXD like this.
  4. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    OOps :eek: I also know why i posted this crap :D
    ..i copied from my old plugin base -.-"
    This is the correct code:
    PHP:
    $sender->getServer()->getPlayer($sender->getName())->getLocation()->pitch
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $sender is already the player object you want.
    iksaku, Legoboy0215 and LDX like this.
  6. MCPEGamerJPatPM
    Offline

    MCPEGamerJPatPM New Member

    Joined:
    Apr 18, 2015
    Posts:
    6
    Minecraft User:
    MCPEGamerJP
    Yawl. thought it was $player
  7. WillotheBlessed
    Offline

    WillotheBlessed Active Member

    Joined:
    Sep 17, 2014
    Posts:
    69
    Minecraft User:
    will
    Ok, why are we even trying to "get" the player's pitch? I am just trying to set a new pitch when i teleport (like for an automated tour of the level, as a camera)

    Here's my code.

    $this->plugin->getLogger()->info("teleporting with pitch of: " .$loc->getPitch());
    $this->cam->teleportImmediate($pos, $loc->getYaw(), $loc->getPitch());

    I have also tried setPositionAndRotation or just the "teleport" and not teleport immediate.

    I've tried using an android device and an iPad... And I've tried looking at the pocketmine source and it seems correct. But whatever happens, the client does not appear to accept the change in pitch. In fact... whatever pitch it has is always canceled and set to zero.

    I'm almost sure this is not a pocketmine issue but a feature of the client, but I wanted to confirm with you fine folks.
  8. WillotheBlessed
    Offline

    WillotheBlessed Active Member

    Joined:
    Sep 17, 2014
    Posts:
    69
    Minecraft User:
    will
    Ok, here's the actual pocketmine code
    public function teleport(Vector3 $pos, $yaw = null, $pitch = null)

    Now... I'm using build #1258.... what version are you using? Because if I try using $player->teleport(x,y,z,yaw,pitch); I get an error. The first parameter must be a Vector3
  9. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    PHP:
    $player->teleport(new Position(x,y,z),yaw,pitch)
    :)
    EvolSoft likes this.
  10. WillotheBlessed
    Offline

    WillotheBlessed Active Member

    Joined:
    Sep 17, 2014
    Posts:
    69
    Minecraft User:
    will
    Yeah, thanks for finally posting a piece of code that will not crash my game, but as I've said, this is not working as intended.
  11. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Have you tried pitch=7 yaw=10?
    I dont know how high the pitch can be
    I made a function so that if i do /loc, i get the Location. I think it was $sender->getLocation->__toString();
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    iksaku and thebigsmileXD like this.
  13. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
  14. WillotheBlessed
    Offline

    WillotheBlessed Active Member

    Joined:
    Sep 17, 2014
    Posts:
    69
    Minecraft User:
    will
    Ok... so I tried this again assuming it would only accept teleport pitchs in radians between -1.57 and 1.57

    Code:
    $nextfloat = rand() / getrandmax();;
    $nextPIAlter = $nextfloat * M_PI;
    $randPitch = (-M_PI * .5) + $nextPIAlter;
    $this->cam->teleport($pos, $loc->getYaw(), $randPitch);
    
    This of course did nothing.
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Try lcg_value() * M_PI
    thebigsmileXD and iksaku like this.
  16. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Also i want to mention, you should not use deg2rad() or rad2deg() in loops, they're kind of slow. Use $rad = ($deg * M_PI / 180) instead.
    But if you only call the function once (i guess you'll only teleport once ;)) you could use them.
    Also, i would use mt_rand or rand instead of lcg_value, but lcg_value is faster.
    (By the way, you can do rand(0,getrandmax()))
    PEMapModder likes this.
  17. WillotheBlessed
    Offline

    WillotheBlessed Active Member

    Joined:
    Sep 17, 2014
    Posts:
    69
    Minecraft User:
    will
    WOW, REALLY FUNNY.

    The point of this thread is that the teleporting of a player with pitch is not working as intended.

    I assume that you two do not have any solutions to the problem... thank you though. Also, great job clicking "like "on each other's posts. I can see that you guys are really pillars of the community, with so many likes to your names.

    Please... either confirm that there is a problem, or show me a solution. I'm not interested in playing forum games.
  18. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    xD Hilarious
  19. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    setRotation ($yaw, $pitch);
    or
    setPositionAndRotation (Vector3 $pos, $yaw, $pitch)
    thebigsmileXD likes this.
  20. WillotheBlessed
    Offline

    WillotheBlessed Active Member

    Joined:
    Sep 17, 2014
    Posts:
    69
    Minecraft User:
    will
    The point is that this is not working! I know what code to write!

Share This Page

Advertisement