mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 10:19:39 +00:00
Interaction checks happen using the plane and not 3d space
This commit is contained in:
parent
82b0dbfe8e
commit
563f6f8e4f
@ -80,6 +80,7 @@ use pocketmine\level\Location;
|
||||
use pocketmine\level\Position;
|
||||
use pocketmine\level\sound\LaunchSound;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Vector2;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\metadata\MetadataValue;
|
||||
use pocketmine\nbt\NBT;
|
||||
@ -1455,10 +1456,14 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
|
||||
public function canInteract(Vector3 $pos, $maxDistance, $maxDiff = 0.5){
|
||||
$dV = $this->getDirectionVector();
|
||||
$dot = $dV->dot($this);
|
||||
$dot1 = $dV->dot($pos);
|
||||
return ($dot1 - $dot) >= -$maxDiff and $this->distanceSquared($pos) <= $maxDistance ** 2;
|
||||
if($this->distanceSquared($pos) > $maxDistance ** 2){
|
||||
return false;
|
||||
}
|
||||
|
||||
$dV = $this->getDirectionPlane();
|
||||
$dot = $dV->dot(new Vector2($this->x, $this->z));
|
||||
$dot1 = $dV->dot(new Vector2($pos->x, $pos->z));
|
||||
return ($dot1 - $dot) >= -$maxDiff;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,6 +40,7 @@ use pocketmine\level\Location;
|
||||
use pocketmine\level\Position;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Math;
|
||||
use pocketmine\math\Vector2;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\metadata\Metadatable;
|
||||
use pocketmine\metadata\MetadataValue;
|
||||
@ -834,7 +835,11 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$x = -$xz * sin(deg2rad($this->yaw));
|
||||
$z = $xz * cos(deg2rad($this->yaw));
|
||||
|
||||
return new Vector3($x, $y, $z);
|
||||
return (new Vector3($x, $y, $z))->normalize();
|
||||
}
|
||||
|
||||
public function getDirectionPlane(){
|
||||
return (new Vector2(-cos(deg2rad($this->yaw) - M_PI_2), -sin(deg2rad($this->yaw) - M_PI_2)))->normalize();
|
||||
}
|
||||
|
||||
public function onUpdate($currentTick){
|
||||
|
@ -115,9 +115,9 @@ class Vector2{
|
||||
}
|
||||
|
||||
public function normalize(){
|
||||
$len = $this->length();
|
||||
$len = $this->lengthSquared();
|
||||
if($len != 0){
|
||||
return $this->divide($len);
|
||||
return $this->divide(sqrt($len));
|
||||
}
|
||||
|
||||
return new Vector2(0, 0);
|
||||
|
@ -206,9 +206,9 @@ class Vector3{
|
||||
* @return Vector3
|
||||
*/
|
||||
public function normalize(){
|
||||
$len = $this->length();
|
||||
$len = $this->lengthSquared();
|
||||
if($len != 0){
|
||||
return $this->divide($len);
|
||||
return $this->divide(sqrt($len));
|
||||
}
|
||||
|
||||
return new Vector3(0, 0, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user