tweaks to headYaw rotation, so it should be nearly perfect now

This commit is contained in:
GameHerobrine 2023-02-23 00:04:25 +03:00
parent a5a0c0e000
commit e4d1898613
5 changed files with 26 additions and 16 deletions

View file

@ -733,6 +733,9 @@ class Entity extends Position
if($this->closed === true){
return false;
}
if($this->lastHeadYaw != $this->headYaw){
$this->sendHeadYaw();
}
$now = microtime(true);
if($this->isStatic === false and ($this->lastX != $this->x or $this->lastY != $this->y or $this->lastZ != $this->z or $this->lastYaw != $this->yaw or $this->lastPitch != $this->pitch or $this->lastHeadYaw != $this->headYaw)){
if($this->class === ENTITY_PLAYER or ($this->last[5] + 8) < $now){
@ -770,15 +773,10 @@ class Entity extends Position
}
} else{
$this->updatePosition();
if($this->lastHeadYaw != $this->headYaw){
$this->sendHeadYaw();
}
$this->updateLast();
}
}
$this->lastUpdate = $now;
}

View file

@ -33,6 +33,7 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
if(!$this->dead && Entity::$allowedAI && $this->idleTime <= 0) {
$this->ai->updateTasks();
}
$this->ai->mobController->rotateTick();
if($this->onGround){
//if(!$this->hasPath() && $this->pathFinder instanceof ITileNavigator){
// $this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y + mt_rand(-1, 1), $this->z + mt_rand(-10, 10), $this->level), 10);

View file

@ -6,6 +6,10 @@ class MobController
* @var Entity
*/
public $entity;
public $finalYaw, $finalPitch, $finalHeadYaw;
public function __construct($e){
$this->entity = $e;
}
@ -36,16 +40,19 @@ 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 +65,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 +73,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);