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

@ -664,7 +664,7 @@ class Entity extends Position
// $this->speedZ = 0; // $this->speedZ = 0;
$this->server->api->handle("entity.move", $this); $this->server->api->handle("entity.move", $this);
$update = true; $update = true;
}elseif ($this->lastYaw != $this->yaw || $this->lastPitch != $this->pitch) { }elseif ($this->lastYaw != $this->yaw || $this->lastPitch != $this->pitch || $this->lastHeadYaw != $this->headYaw) {
$update = true; $update = true;
} }
@ -723,7 +723,9 @@ class Entity extends Position
if($this->idleTime > 0){ if($this->idleTime > 0){
-- $this->idleTime; -- $this->idleTime;
} }
if($this->lastHeadYaw != $this->headYaw){
$this->sendHeadYaw();
}
if($this->class !== ENTITY_PLAYER && $update){ if($this->class !== ENTITY_PLAYER && $update){
$this->updateMovement(); $this->updateMovement();
} }
@ -769,9 +771,6 @@ class Entity extends Position
} }
} else{ } else{
$this->updatePosition(); $this->updatePosition();
if($this->lastHeadYaw != $this->headYaw){
$this->sendHeadYaw();
}
$this->updateLast(); $this->updateLast();
} }

View file

@ -33,6 +33,7 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
if(!$this->dead && Entity::$allowedAI && $this->idleTime <= 0) { if(!$this->dead && Entity::$allowedAI && $this->idleTime <= 0) {
$this->ai->updateTasks(); $this->ai->updateTasks();
} }
$this->ai->mobController->rotateTick();
if($this->onGround){ if($this->onGround){
//if(!$this->hasPath() && $this->pathFinder instanceof ITileNavigator){ //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); // $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,9 @@ class MobController
* @var Entity * @var Entity
*/ */
public $entity; public $entity;
public $finalYaw, $finalPitch, $finalHeadYaw;
public function __construct($e){ public function __construct($e){
$this->entity = $e; $this->entity = $e;
} }
@ -36,16 +39,17 @@ class MobController
} }
} }
} }
$this->faceEntity($this->entity->add($ox, $oy, $oz));
if($this->entity->knockbackTime <= 0){ if($this->entity->knockbackTime <= 0){
$this->entity->moveEntityWithOffset($ox, $oy, $oz); $this->entity->moveEntityWithOffset($ox, $oy, $oz);
} }
$this->faceEntity($this->entity->add($ox, $oy, $oz));
return true; 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){ public function moveTo($x, $y, $z){
return $this->moveNonInstant($x - floor($this->entity->x), $y - floor($this->entity->y), $z - floor($this->entity->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))); $tan = $dz == 0 ? ($dx < 0 ? 180 : 0) : (90 - rad2deg(atan($dx / $dz)));
$thetaOffset = $dz < 0 ? 90 : 270; $thetaOffset = $dz < 0 ? 90 : 270;
$calcYaw = ($thetaOffset + $tan); $calcYaw = ($thetaOffset + $tan);
$this->entity->headYaw = $this->entity->yaw = $calcYaw; $this->finalHeadYaw = $this->entity->yaw = $calcYaw;
} }
public function lookOffset($x, $y, $z, $pitch = true){ public function lookOffset($x, $y, $z, $pitch = true){
@ -66,7 +70,7 @@ class MobController
$thetaOffset = $z < 0 ? 90 : 270; $thetaOffset = $z < 0 ? 90 : 270;
$calcYaw = $tan + $thetaOffset; $calcYaw = $tan + $thetaOffset;
$this->entity->yaw = $this->entity->headYaw = $calcYaw; $this->entity->yaw = $this->finalHeadYaw = $calcYaw;
if($pitch){ if($pitch){
$diff = sqrt($x * $x + $z * $z); $diff = sqrt($x * $x + $z * $z);

View file

@ -24,7 +24,7 @@ class RotateHeadPacket extends RakNetDataPacket{
$this->putInt(count($this->entities)); $this->putInt(count($this->entities));
foreach($this->entities as $d){ foreach($this->entities as $d){
$this->putInt($d[0]); //eid $this->putInt($d[0]); //eid
$this->putByte((int) ($d[1] / 360 / 0.0039062)); $this->putByte((int) ($d[1] / 360 / 0.0039062)); //wraps 360 angle to 0xff
} }
} }

View file

@ -39,10 +39,16 @@ class Utils{
return $id; return $id;
} }
public static function wrapAngleTo180_float($par0) public static function wrapAngleTo360($angle)
{ {
$par0 %= 360.0; $angle %= 360;
return $par0 >= 180 ? $par0 - 360 : (($par0 < -180) ? ($par0 + 360) : $par0); return $angle < 0 ? $angle + 360 : $angle;
}
public static function wrapAngleTo180($angle)
{
$angle = fmod($angle+180, 360);
return $angle < 0 ? $angle + 360 : $angle - 180;
} }
public static function getSign($v){ public static function getSign($v){