pocketmine\math\Vector3::add PHP Method

add() public method

public add ( Vector3 | integer $x, integer $y, integer $z ) : Vector3
$x Vector3 | integer
$y integer
$z integer
return Vector3
    public function add($x, $y = 0, $z = 0)
    {
        if ($x instanceof Vector3) {
            return new Vector3($this->x + $x->x, $this->y + $x->y, $this->z + $x->z);
        } else {
            return new Vector3($this->x + $x, $this->y + $y, $this->z + $z);
        }
    }

Usage Example

Beispiel #1
0
 public function onUpdate($currentTick)
 {
     if ($this->closed !== false) {
         return false;
     }
     $this->lastUpdate = $currentTick;
     $this->timings->startTiming();
     $hasUpdate = true;
     //parent::onUpdate($currentTick);
     if ($this->isAlive()) {
         $expectedPos = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ);
         $expBlock0 = $this->getLevel()->getBlock($expectedPos->add(0, -1, 0)->round());
         $expBlock1 = $this->getLevel()->getBlock($expectedPos->add(0, 0, 0)->round());
         if ($expBlock0->getId() == 0) {
             $this->motionY -= $this->gravity;
             //重力计算
             $this->motionX = 0;
             $this->motionZ = 0;
         } else {
             $this->motionY = 0;
         }
         if ($expBlock1->getId() != 0) {
             $this->motionY += 0.1;
         }
         $this->move($this->motionX, $this->motionY, $this->motionZ);
         if ($this->isFreeMoving) {
             $this->motionX = 0;
             $this->motionZ = 0;
             $this->isFreeMoving = false;
         }
         /*$friction = 1 - $this->drag;
         
         			$this->motionX *= $friction;
         			$this->motionY *= 1 - $this->drag;
         			$this->motionZ *= $friction;*/
         $f = sqrt($this->motionX ** 2 + $this->motionZ ** 2);
         $this->yaw = -atan2($this->motionX, $this->motionZ) * 180 / M_PI;
         //视角计算
         //$this->pitch = (-atan2($f, $this->motionY) * 180 / M_PI);
         $this->updateMovement();
     }
     $this->timings->stopTiming();
     return $hasUpdate or !$this->onGround or abs($this->motionX) > 1.0E-5 or abs($this->motionY) > 1.0E-5 or abs($this->motionZ) > 1.0E-5;
 }
All Usage Examples Of pocketmine\math\Vector3::add