pocketmine\Player::setMotion PHP Method

setMotion() public method

public setMotion ( Vector3 $mot )
$mot pocketmine\math\Vector3
    public function setMotion(Vector3 $mot)
    {
        if (parent::setMotion($mot)) {
            if ($this->chunk !== null) {
                $this->level->addEntityMotion($this->chunk->getX(), $this->chunk->getZ(), $this->getId(), $this->motionX, $this->motionY, $this->motionZ);
                $pk = new SetEntityMotionPacket();
                $pk->entities[] = [0, $mot->x, $mot->y, $mot->z];
                $this->dataPacket($pk);
            }
            if ($this->motionY > 0) {
                $this->startAirTicks = -log($this->gravity / ($this->gravity + $this->drag * $this->motionY)) / $this->drag * 2 + 5;
            }
            return true;
        }
        return false;
    }

Usage Example

Example #1
0
 public function move(Player $p, Vector3 $m, $t, $cool, $tt = false)
 {
     if (!$tt) {
         $tt = 0;
     }
     if ($t - $tt < 1) {
         return;
     } else {
         $tt++;
         $p->setMotion($m);
         $p->onGround = true;
         if ($t - $tt > 0) {
             $this->getServer()->getScheduler()->scheduleDelayedTask(new CallbackTask([$this, "move"], [$p, $m, $t, $cool, $tt]), $cool * 20);
         }
     }
 }
Player