mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-01 07:39:57 +00:00
Added Living->lookAt()
This commit is contained in:
parent
e055ce9526
commit
8daa8deae9
@ -632,4 +632,23 @@ abstract class Living extends Entity implements Damageable{
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the entity's yaw and pitch to make it look at the specified Vector3 position. For mobs, this will cause
|
||||||
|
* their heads to turn.
|
||||||
|
*
|
||||||
|
* @param Vector3 $target
|
||||||
|
*/
|
||||||
|
public function lookAt(Vector3 $target) : void{
|
||||||
|
$horizontal = sqrt(($target->x - $this->x) ** 2 + ($target->z - $this->z) ** 2);
|
||||||
|
$vertical = $target->y - $this->y;
|
||||||
|
$this->pitch = -atan2($vertical, $horizontal) / M_PI * 180; //negative is up, positive is down
|
||||||
|
|
||||||
|
$xDist = $target->x - $this->x;
|
||||||
|
$zDist = $target->z - $this->z;
|
||||||
|
$this->yaw = atan2($zDist, $xDist) / M_PI * 180 - 90;
|
||||||
|
if($this->yaw < 0){
|
||||||
|
$this->yaw += 360.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user