diff --git a/src/entity/Living.php b/src/entity/Living.php index d5f169b11..889e55fa2 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -808,14 +808,17 @@ 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 + $this->getEyeHeight()); - $this->location->pitch = -atan2($vertical, $horizontal) / M_PI * 180; //negative is up, positive is down + $pitch = -atan2($vertical, $horizontal) / M_PI * 180; //negative is up, positive is down $xDist = $target->x - $this->location->x; $zDist = $target->z - $this->location->z; - $this->location->yaw = atan2($zDist, $xDist) / M_PI * 180 - 90; - if($this->location->yaw < 0){ - $this->location->yaw += 360.0; + + $yaw = atan2($zDist, $xDist) / M_PI * 180 - 90; + if($yaw < 0){ + $yaw += 360.0; } + + $this->setRotation($yaw, $pitch); } protected function sendSpawnPacket(Player $player) : void{ diff --git a/src/entity/Squid.php b/src/entity/Squid.php index 063e87b16..39e2a3637 100644 --- a/src/entity/Squid.php +++ b/src/entity/Squid.php @@ -113,8 +113,10 @@ class Squid extends WaterAnimal{ } $f = sqrt(($this->motion->x ** 2) + ($this->motion->z ** 2)); - $this->location->yaw = (-atan2($this->motion->x, $this->motion->z) * 180 / M_PI); - $this->location->pitch = (-atan2($f, $this->motion->y) * 180 / M_PI); + $this->setRotation( + -atan2($this->motion->x, $this->motion->z) * 180 / M_PI, + -atan2($f, $this->motion->y) * 180 / M_PI + ); } return $hasUpdate; diff --git a/src/entity/projectile/Projectile.php b/src/entity/projectile/Projectile.php index 1fa1071f9..1f652bda4 100644 --- a/src/entity/projectile/Projectile.php +++ b/src/entity/projectile/Projectile.php @@ -253,8 +253,10 @@ abstract class Projectile extends Entity{ //recompute angles... $f = sqrt(($this->motion->x ** 2) + ($this->motion->z ** 2)); - $this->location->yaw = (atan2($this->motion->x, $this->motion->z) * 180 / M_PI); - $this->location->pitch = (atan2($this->motion->y, $f) * 180 / M_PI); + $this->setRotation( + atan2($this->motion->x, $this->motion->z) * 180 / M_PI, + atan2($this->motion->y, $f) * 180 / M_PI + ); } $this->getWorld()->onEntityMoved($this);