Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Entity look at Vector3!

Comments in 'Plugin Development' started by Primus, Mar 20, 2016.

  1. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Not good at math. Any code?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Got a time to test it and ...

    This look when I'm not in NPC vision radius (4 blocks).
    [​IMG]
    And this happens when the code has ran (After going into his vision radius)
    [​IMG]
    Lets move a bit to left or right
    [​IMG]
    And a bit more to left ...
    [​IMG]

    Here is the code.
    PHP:
    public function updateMove()
      {
      
    $this->level->addEntityMovement($this->>> 4$this->>> 4$this->getId(), $this->x$this->0.49000001$this->z$this->yaw$this->pitch$this->yaw);
      if (
    $this->!== $this->lastX or $this->!== $this->lastY or $this->!== $this->lastZ or $this->yaw !== $this->lastYaw or $this->pitch !== $this->lastPitch) {
      
    $event = new \pocketmine\event\entity\EntityMotionEvent($this, new \pocketmine\math\Vector3($this->$this->lastX$this->$this->lastY$this->$this->lastZ));
      
    $this->server->getPluginManager()->callEvent($event);
      if (
    $event->isCancelled()) return;
      
    $this->lastX $this->target->getX();
      
    $this->lastY $this->target->getY();
      
    $this->lastZ $this->target->getZ();
      
    $this->lastYaw $this->yaw;
      
    $this->lastPitch $this->pitch;
      
    $pk = new \pocketmine\network\protocol\MovePlayerPacket();
      
    $pk->eid $this->id;
      
    $pk->$this->x;
      
    $pk->$this->y;
      
    $pk->$this->z;
      
    $pk->yaw $this->yaw;
      
    $pk->pitch $this->pitch;
      
    $pk->bodyYaw $this->yaw;
      foreach (
    $this->hasSpawned as $player) {
      
    $player->dataPacket($pk);
      }
      }
      }

      public function 
    onUpdate($currentTick)
      {
      if(!
    $this->target){
      
    $this->getChaseTarget();
      } else {
      if(
    $this->distance($this->target) >= or !$this->target->isConnected()){
      
    $this->target null;
      } else {
      
    $delta $this->target->subtract($this);
      
    $pitch rad2deg(asin($delta->1.68));
      
    $yaw rad2deg(asin(-$delta->$delta->z));
      
    $this->yaw $yaw;
      
    $this->pitch $pitch;
      
    $this->updateMove();
      }
      }
    // Further ...
    minebuilder0110 likes this.

Share This Page

Advertisement