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. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    It's only two choices left:
    1. Delete game
    2. Blame @shoghicp
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Try
    PHP:
    $player->teleport(); // Anywhere you want
    $entityId $player->getId();
    $y $player->getFloorY();
    $z $player->getFloorZ();
    $x $player->getFloorX();
    $yaw 5.6;
    $pitch 36;
    $player->addEntityMovement ($entityId$x$y$z$yaw$pitch);
    $player->updateMovement(); // I think this is useless.
    thebigsmileXD likes this.
  3. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    I will never blame Shoghicp.
    The only thing we wanted to do was helping you. I'll test some code today and maybe i find a solution.
    And about the liking: its not a game, its supporting each others code snippets, so you can see that it maybe works..
    If you want help, you cant ask, but dont say that, thats so.. Bleh
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The best way to see why you can't set something is to get it. What we are trying to tell you is that you should use degrees instead of radians.
    thebigsmileXD likes this.
  5. WillotheBlessed
    Offline

    WillotheBlessed Active Member

    Joined:
    Sep 17, 2014
    Posts:
    69
    Minecraft User:
    will
    yes, that line is useless... because it is a protected method and I can't call it. Also, inside the source code, the method is not yet implemented.
  6. WillotheBlessed
    Offline

    WillotheBlessed Active Member

    Joined:
    Sep 17, 2014
    Posts:
    69
    Minecraft User:
    will
    Here is my code... it is supposed to teleport with a random pitch between -90 and 90.

    This does NOT set the pitch.
    Code:
    $pos = new Position($loc->x, $loc->y, $loc->z,$this->plugin->getServer()->getDefaultLevel());
    $nextfloat = rand() / getrandmax();;
    $nextPIAlter = $nextfloat * M_PI;
    $randPitch = (-M_PI * .5) + $nextPIAlter;
    $randPitch = $randPitch * (180/M_PI);
    $this->cam->teleport($pos, $loc->getYaw(), $randPitch);
    $this->cam->setPositionAndRotation($pos, $loc->getYaw(), $randPitch);
    $this->plugin->getLogger()->info("teleporting with pitch of: " . $randPitch);
    $entityId = $this->cam->getId();
    $y = $this->cam->getX();
    $z = $this->cam->getZ();
    $x = $this->cam->getX();
    $pitch = $randPitch;
    $this->cam->addEntityMovement($entityId, $x, $y, $z, $loc->getYaw(), $pitch);
    
    Yes, I realize this code is not efficient, so please do not correct or try to optimize it. I only want to know how the pitch needs to be set, then I can write optimized code.
  7. udwarf
    Offline

    udwarf Active Member

    Joined:
    Apr 17, 2016
    Posts:
    61
    Minecraft User:
    1Zaza
    Is it fixed already? I'm experiencing the same problem with 0.14.x version: after teleportation player's pitch always 0
    I'm trying such code without success:
    PHP:
    $player->teleport($pos$pos->getYaw(), $pos->getPitch());
    $player->setRotation($pos->getYaw(), $pos->getPitch());
    where pos is a Location object:
    Location (level=null, x=522.5, y=110, z=46, yaw=0, pitch=90)
    Last edited: Jul 3, 2016

Share This Page

Advertisement