Include eye height in Living->lookAt() calculation (#4440)

This commit is contained in:
marshall 2021-09-09 04:54:32 +08:00 committed by GitHub
parent dca5a9d8ea
commit b9b1ba9526
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -772,7 +772,7 @@ abstract class Living extends Entity{
*/
public function lookAt(Vector3 $target) : void{
$horizontal = sqrt(($target->x - $this->location->x) ** 2 + ($target->z - $this->location->z) ** 2);
$vertical = $target->y - $this->location->y;
$vertical = $target->y - ($this->location->y + $this->getEyeHeight());
$this->location->pitch = -atan2($vertical, $horizontal) / M_PI * 180; //negative is up, positive is down
$xDist = $target->x - $this->location->x;