I want to scatter players around the world based on a disatance from the world spawn point(or otherwise called radius) i know i have to check the blocks under and somewhat around the player, but how would i go about doing this?
I got a different method from https://bukkit.org/threads/random-location-within-a-radius-not-a-square-area.131423/#post-1563032 and converted it to PHP PHP: /** * @return Position */ public function getNewSpawnPoint(){ $rndGen = new Random(); $r = $rndGen->nextBoundedInt($this->getBorder()); $x = $rndGen->nextBoundedInt($r); $z = sqrt(pow($r,2) - pow($x,2)); if($rndGen->nextBoolean()) $x *= -1; if($rndGen->nextBoolean()) $z *= -1; return new Position($x, 256, $z, $this->getLevelByName()); } my only problem is getting a Y i know i have to check if the the block(s) around the player are "safe" ones but i dont know how to go about it somewhat
That doesn't look uniformly random. Let me make a randomness scattetplot based on your algorithm: There is almost zero chance that a point in the horizontal axis is selected, and the points are highly converged towards the center. You should generate r² and yaw uniformly, instead of r and cos(yaw). Otherwise you'd get something like that image
If you use the algorithm I linked above (uniform r², uniform theta), you get something like this instead: