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

How do i get the yaw and pitch from a Vector3?

Discussion in 'Development' started by whoami, Aug 13, 2021.

  1. whoami

    whoami Creeper

    Messages:
    1
    GitHub:
    jsismylife
    So i am trying to make an KillAura detection and for that i want to calculate the yaw and pitch needed to look at the Players (x,y,z) coordinate but neither of my atempts are returing the right yaw and pitch.

    Here is some of my code:

    /* 1st try
    $yaw = atan($playerPos[1] / $playerPos[0]);
    $pitch = atan(sqrt(pow($playerPos[0], 2) + pow($playerPos[1], 2)) / $playerPos[2]);
    */

    /* 2nd try
    $dx = $damagerPos[0] - $playerPos[0];
    $dy = $damagerPos[1] - $playerPos[1];
    $dz = $damagerPos[2] - $playerPos[2];

    $pitch = -atan2($dy, sqrt(($dx * $dx) + ($dz * $dz)));
    $yaw = atan2($dz, $dx) - 90;
    */

    /* 3rd try
    $pitch = rad2deg(atan2(-$playerPos[0], $playerPos[2]));
    $yaw = rad2deg(-$playerPos[1]);
    */

    /* 4th try
    $pitch = $damager->pitch * M_PI / 180 * -1;
    $yaw = ($damager->yaw + 90) * M_PI / 180;
    */

    /* 5th try
    $dx = $damagerPos[0] - $playerPos[0];
    $dy = $damagerPos[1] - $playerPos[1];
    $dz = $damagerPos[2] - $playerPos[2];

    $pitch = asin(-$dy);
    $yaw = atan2($dx, $dz);
    */

    /* 6th try
    $delta = $player->subtract($damager);
    $pitch = rad2deg(asin($delta->y));
    $yaw = rad2deg(atan(-$delta->x / $delta->z));
    */

    /* 7th try
    $pitch = asin($playerPos[0] / cos(asin($playerPos[1])));
    $yaw = asin($playerPos[1]);
    */

    /* 8th try
    $dx = $damagerPos[0] - $playerPos[0];
    $dy = $damagerPos[1] - $playerPos[1];
    $dz = $damagerPos[2] - $playerPos[2];

    $pitch = atan2(sqrt($dz * $dz + $dx * $dx), $dy) + M_PI;
    $yaw = atan2($dz, $dx);
    */

    /* 9th try
    $pitch = atan(sqrt(pow($playerPos[0], 2) + pow($playerPos[1], 2)) / $playerPos[2]);
    $yaw = atan($playerPos[0] / (-$playerPos[1]));
    */

    Note: I know that there might be better ways of detecting KillAura but i want to do it this way beacuse i want to learn how i can get the yaw and pitch from a Vector3.

    Sorry for my english xD
     
  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.