Get random coordinates in x meter radius from player
#1

Hello, have you any idea how to get random coordinates in x meter radius from player?

For example, imagine a circle, with player in the middle (centre) and how to get random coordinates in the circle? Remember, this is not for detecting if the player is in the range of something, but rather to get random coordinates within the circle.
Reply
#2

First, get a random distance, between 0.0 and the maximum allowed (radius of the circle).
Then get a random angle (between 0 and 360 degrees).
After that use sin and cos to determine the coordinates.

Pseudo-code (don't take this literally):
Код:
new Float:Angle = random(360.0);
new Float:x = cos(Angle);
new Float:y = sin(Angle);
new Float:Distance = random(Radius);
new Float:LocX = (x * Distance) + PlayerX;
new Float:LocY = (y * Distance) + PlayerY;
LocX and LocY would hold the random coordinates in the specified radius around the player.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)