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

Direction

Discussion in 'Development' started by LucGamesDE, May 14, 2017.

  1. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    How can I change the direction where a player is looking at?
     
  2. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    Perhaps this could be helpful?
     
  3. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    I don't want to rotate the player. I want him to look to x for example
     
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    As far as I remember PocketMine doesn't store the yaw and head yaw separately. An explicit packet with a different head yaw is probably needed.
     
  5. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    If you do /hub on lbsg your had look to the lbsg logo. And I want to do that too
     
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    This is player rotation.
     
  7. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    But what do I need to rotate the player to x?
     
  8. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    On LBSG, you are teleported to a set location. Player::teleport() will work for you with the set pitch and yaw parameters
     
  9. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    ...except for a client-sided bug where pitch doesn't work properly... >_< https://github.com/pmmp/PocketMine-MP/issues/821
     
  10. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
  11. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    And how do I define yaw?
     
  12. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
  13. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
  14. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    You'll have to calculate how to set the yaw to make the player look at the wanted x coordinate. So you don't want to set it to x, but to a value which depends on x.
     
  15. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    There was a helper function in Utils.php to help you evaluate the yaw and pitch from relative positions, but :shoghi: commented it out for some reason... (during the API 1.0.0 rewrite)

    So, looking at $pos2 from $pos1:
    PHP:
    $diff $pos2->subtract($pos1)->normalize(); // now a unit vector
    $pitch asin(-$diff->y);
    $yaw acos($diff->cos($pitch));
    Note that asin() and acos() return values in radians, so before you apss $pitch and $yaw to the player methods, you have to rad2deg() them first, or simply ($yaw / M_PI * 180).
     
    jasonwynn10 and corytortoise like this.
  16. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    If it was commented out, can it be put back? It seems like it's useful.
     
  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.