Hi all, when I use the function getPosition of an Entity, what does this position represent? The middle of the entity? I think the y-coordinate is the coordinate of the feet of the entity right? But where is x and z measured? Top left, Top right? I need the information to get correct information on the block which is in front of the entity. Sometimes, entities overlap blocks. So when getting the block in front of the entity, sometimes i get another block (the block behind the first block in line) when e.g. using the BlockIterator. Anyway - here's a small sample code snippet (while this is an Entity): Code: $directionBlock = null; $currentBlock = $this->level->getBlock($this->temporalVector->setComponents(Math::floorFloat($this->x), Math::floorFloat($this->y), Math::floorFloat($this->z))); switch($this->getDirection()) { case 2: // NORTH $directionBlock = $this->level->getBlock($currentBlock->add(-1 - ($this->length / 2), 0, 0)); break; case 0: // SOUTH $directionBlock = $this->level->getBlock($currentBlock->add(1 + ($this->length / 2), 0, 0)); break; case 1: // WEST $directionBlock = $this->level->getBlock($currentBlock->add(0, 0,2 + ($this->length / 2))); break; case 3: // EAST $directionBlock = $this->level->getBlock($currentBlock->add(0, 0,-2 - ($this->length / 2))); break; } Direction is taken into account. But i personally think, that only using the position of the entity is the wrong way? Maybe we need to divide something through the length and width of the entity? Any help appreciated
You may use AxisAlignedBB https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/math/AxisAlignedBB.php
Noooo, you are recreating a function. Don't do that. Just.. PHP: /** @var Player $player */$maxDistance = 100;$block = $player->getTargetBlock($maxDistance); Position represents the feet of the entity.
It seems it is working (not in each case, but in general). Thanks for your answers! Using now getTargetBlock - although it uses the heavy weighted BlockIterator.