mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 08:17:34 +00:00
Avoid direct mutations of Entity->location
This commit is contained in:
parent
345ac75aac
commit
fc53f3721a
@ -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{
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user