For example, the "certain player" is me. How to knockback all players off me when they come near to me? According to the rules of the forum i have to attach my attempts. But everything i have only one guess. I think i can do it using distance, setMotion, getDirectionVector()->subtract() And here is my attempt PHP: public function onMove(PlayerMoveEvent $e){ if($e->getPlayer()->isOp()){ $pl = $e->getPlayer(); foreach($this->getServer()->getOnlinePlayers() as $players){ if($players->distance(new Vector3($pl->x, $pl->y, $pl->z)) <= 5){ if(!$players->isOp()){ $players->setMotion($players->getDirectionVector()->subtract()); } } } } }
So, maybe someone will write something? Because code i provided is pushing players in direction that they are look. How to reverse this?
I think you meant: PHP: $f = 1.8;$players->setMotion($pl->subtract($players)->normalize()->multiply($f)); $f is proportional to the knockback distance.
Yes, I asked some tips from my friend, he gave me "setMotion", "distance", and "subtract". Since I dont know Vector3 base logic I dont know how it works. But I attempted to use it in practice anyway
Player->getDirectionVector() is the vector from the player to the block he is facing, while Player->subtract(Player) gives the vector from one player to another.