mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
head yaw fixed
This commit is contained in:
parent
1ac7179a97
commit
9d6322f587
4 changed files with 47 additions and 6 deletions
|
|
@ -1242,6 +1242,7 @@ class Entity extends Position
|
|||
$this->last[3] = $this->yaw;
|
||||
$this->last[4] = $this->pitch;
|
||||
$this->last[5] = microtime(true);
|
||||
$this->lastHeadYaw = $this->headYaw;
|
||||
}
|
||||
|
||||
public function getPosition($round = false)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ abstract class Living extends Entity implements Pathfindable{
|
|||
public $jumpMovementFactor = 0.02; //TODO may not be constant
|
||||
public $aiMoveSpeed;
|
||||
|
||||
public $renderYawOffset = 0.0; //used by head rotation, TODO better name
|
||||
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
$this->target = false;
|
||||
|
|
@ -131,6 +132,9 @@ abstract class Living extends Entity implements Pathfindable{
|
|||
if(self::$entityPushing){
|
||||
$this->collideHandler();
|
||||
}
|
||||
|
||||
//Yaw rotation in 1.5 is handled in a bit different place but hopefully this will work too
|
||||
$this->ai->mobController->updateHeadYaw();
|
||||
}
|
||||
|
||||
public function moveEntityWithHeading($strafe, $forward){
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ class MobController
|
|||
|
||||
public $finalYaw, $finalPitch, $finalHeadYaw;
|
||||
|
||||
public $headYaw;
|
||||
public $someTicker = 0;
|
||||
|
||||
protected $jumping;
|
||||
protected $jumpTimeout;
|
||||
|
||||
|
|
@ -53,7 +56,14 @@ class MobController
|
|||
public function canJump(){
|
||||
return $this->isJumping() && $this->jumpTimeout <= 0 && $this->entity->onGround;
|
||||
}
|
||||
|
||||
public static function limitAngle2($old, $newA, $limit){
|
||||
$v4 = Utils::wrapAngleTo180($old - $newA);
|
||||
|
||||
if($v4 < -$limit) $v4 = -$limit;
|
||||
if($v4 >= $limit) $v4 = $limit;
|
||||
|
||||
return $old - $v4;
|
||||
}
|
||||
public static function limitAngle($old, $newA, $limit){
|
||||
$v4 = Utils::wrapAngleTo180($newA - $old);
|
||||
|
||||
|
|
@ -77,9 +87,7 @@ class MobController
|
|||
|
||||
if($v8 >= 2.500000277905201E-7){ //TODO convert notation
|
||||
$v10 = (atan2($diffZ, $diffX) * 180 / M_PI) - 90;
|
||||
console("$v10: ".$v10);
|
||||
$this->entity->yaw = self::limitAngle($this->entity->yaw, $v10, 30);
|
||||
console("yaw: {$this->entity->yaw}");
|
||||
$this->entity->setAIMoveSpeed($this->speed * $this->entity->getSpeedModifer());
|
||||
|
||||
if($diffY > 0 && $diffX*$diffX + $diffZ*$diffZ < 1) $this->setJumping(true);
|
||||
|
|
@ -93,7 +101,35 @@ class MobController
|
|||
//if($this->jumpTimeout > 0) --$this->jumpTimeout;
|
||||
}
|
||||
|
||||
public function updateHeadYaw(){
|
||||
$diffX = $this->entity->x - $this->entity->lastX;
|
||||
$diffZ = $this->entity->z - $this->entity->lastZ;
|
||||
if(($diffX*$diffX + $diffZ*$diffZ) > 2.500000277905201E-7){ //TODO convert notation
|
||||
$this->entity->renderYawOffset = $this->entity->yaw;
|
||||
$this->entity->headYaw = self::limitAngle2($this->entity->renderYawOffset, $this->entity->headYaw, 75);
|
||||
$this->headYaw = $this->entity->headYaw;
|
||||
$this->someTicker = 0;
|
||||
}else{
|
||||
$v5 = 75;
|
||||
if(abs($this->entity->headYaw - $this->headYaw) > 15){
|
||||
$this->someTicker = 0;
|
||||
$this->headYaw = $this->entity->headYaw;
|
||||
}else{
|
||||
++$this->someTicker;
|
||||
|
||||
if($this->someTicker > 10){
|
||||
$v5 = max(1 - ($this->someTicker - 10) / 10, 0) * 75;
|
||||
}
|
||||
}
|
||||
$this->entity->renderYawOffset = self::limitAngle2($this->entity->headYaw, $this->entity->renderYawOffset, $v5);
|
||||
}
|
||||
$this->entity->headYaw = $this->entity->renderYawOffset;
|
||||
}
|
||||
|
||||
public function rotateTick(){ //TODO handle more rotation
|
||||
|
||||
|
||||
|
||||
//$this->entity->lastHeadYaw = $this->entity->headYaw;
|
||||
//$w180 = Utils::wrapAngleTo180($this->finalHeadYaw - $this->entity->headYaw);
|
||||
//$w180min = min(abs($w180), 20)*Utils::getSign($w180);
|
||||
|
|
|
|||
|
|
@ -10,13 +10,13 @@ class TaskRandomWalk extends TaskBase
|
|||
|
||||
public function onStart(EntityAI $ai)
|
||||
{
|
||||
$this->x = mt_rand(-10, 10);
|
||||
$this->z = mt_rand(-10, 10);
|
||||
$this->x = mt_rand(-1, 1);
|
||||
$this->z = mt_rand(-1, 1);
|
||||
if($this->x === 0 && $this->z === 0){
|
||||
$this->reset();
|
||||
return false;
|
||||
}
|
||||
$this->selfCounter = floor(5 * Utils::distance($ai->entity, $ai->entity->add($this->x, 0, $this->z)));
|
||||
$this->selfCounter = mt_rand(80, 100);
|
||||
}
|
||||
|
||||
public function onEnd(EntityAI $ai)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue