headYaw rot changes

This commit is contained in:
GameHerobrine 2023-02-23 00:41:01 +03:00
parent 1b0366802f
commit 447638816e
5 changed files with 26 additions and 16 deletions

View file

@ -6,6 +6,9 @@ class MobController
* @var Entity
*/
public $entity;
public $finalYaw, $finalPitch, $finalHeadYaw;
public function __construct($e){
$this->entity = $e;
}
@ -36,16 +39,17 @@ class MobController
}
}
}
$this->faceEntity($this->entity->add($ox, $oy, $oz));
if($this->entity->knockbackTime <= 0){
$this->entity->moveEntityWithOffset($ox, $oy, $oz);
}
$this->faceEntity($this->entity->add($ox, $oy, $oz));
return true;
}
public function rotateTick(){ //TODO handle more rotation
$w180 = Utils::wrapAngleTo180($this->finalHeadYaw - $this->entity->headYaw);
$w180min = min(abs($w180), 20)*Utils::getSign($w180);
$this->entity->headYaw = Utils::wrapAngleTo360($this->entity->headYaw + $w180min);
}
public function moveTo($x, $y, $z){
return $this->moveNonInstant($x - floor($this->entity->x), $y - floor($this->entity->y), $z - floor($this->entity->z));
}
@ -58,7 +62,7 @@ class MobController
$tan = $dz == 0 ? ($dx < 0 ? 180 : 0) : (90 - rad2deg(atan($dx / $dz)));
$thetaOffset = $dz < 0 ? 90 : 270;
$calcYaw = ($thetaOffset + $tan);
$this->entity->headYaw = $this->entity->yaw = $calcYaw;
$this->finalHeadYaw = $this->entity->yaw = $calcYaw;
}
public function lookOffset($x, $y, $z, $pitch = true){
@ -66,7 +70,7 @@ class MobController
$thetaOffset = $z < 0 ? 90 : 270;
$calcYaw = $tan + $thetaOffset;
$this->entity->yaw = $this->entity->headYaw = $calcYaw;
$this->entity->yaw = $this->finalHeadYaw = $calcYaw;
if($pitch){
$diff = sqrt($x * $x + $z * $z);