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

Set rotation of an players, so it looks towards another player

Discussion in 'Development' started by SkyZone, Jan 30, 2018.

  1. SkyZone

    SkyZone Slime

    Messages:
    95
    I have the $player1 var and $player2 var. Now i want that $player1 looks at $player2. How to to that?
    I tried setRotation, but i didnt figure out, how to set the rotation properly...
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Check how BlockPets does it: https://github.com/BlockHorizons/Bl...rizons/BlockPets/pets/WalkingPet.php#L66-#L67
    Extracted code:
    PHP:
    $x $petOwner->$this->xOffset $this->x;
    $y $petOwner->$this->y;
    $z $petOwner->$this->zOffset $this->z;
    $this->yaw rad2deg(atan2(-$x$z));
    $this->pitch rad2deg(-atan2($ysqrt($x $x $z $z)));
    Yaw and pitch is what you need. You can ignore the xOffset and zOffset I think, setRotation() should handle that.
     
  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.