Getting random cordinates within a checkpoint - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Getting random cordinates within a checkpoint (
/showthread.php?tid=587705)
Getting random cordinates within a checkpoint -
HBG - 02.09.2015
I am trying to find a way to drop an object at a random point within a large checkpoint. The checkpoint spawns at a random location and starts at a radius of about 200 and slowly gets smaller as the game proceeds. I have tried to no avail of generating a random x and y cordinate within the checkpoint making an array for example will not work as the checkpoint spawns at a complete random location every time. Is there anyone out there good with math that can help point me in the right direction?
I will be using the mapandreas plugin to find the z cordinate and that is why I just need a way to generate an X and Y cordinate within a checkpoint.
Re: Getting random cordinates within a checkpoint -
SickAttack - 02.09.2015
Even if it's random, you can still save the checkpoint's position. With that position, you have everything you would ever need to accomplish this task.
Re: Getting random cordinates within a checkpoint -
HBG - 02.09.2015
Quote:
Originally Posted by SickAttack
Even if it's random, you can still save the checkpoint's position. With that position, you have everything you would ever need to accomplish this task.
|
Yes I know I have everything I need to accomplish this task I am just not sure how to do it. Can you be a little more specific? I don't need you to write code out for me but a bit more detail on how to do this would be nice.
Re: Getting random cordinates within a checkpoint -
Vince - 02.09.2015
PHP код:
new const checkPointRadius = 15;
new
Float:randomAngle = float(random(360)),
Float:randomDistance = random(checkPointRadius);
new
Float:dropX = checkPointX + floatsin(-randomAngle, degrees) * randomDistance,
Float:dropY = checkPointY + floatcos(-randomAngle, degrees) * randomDistance,
Float:dropZ = checkPointZ + 0.5;
Something like that should work. This picks a random angle between 0 and 360 (a full circle, as you know) and a random distance between 0 and the size of the radius of the checkpoint. Then some trig is done to calculate the coordinates at the specified angle and the specified distance. Can't really explain that. Rather mathematically complex.
Re: Getting random cordinates within a checkpoint -
HBG - 02.09.2015
Quote:
Originally Posted by Vince
PHP код:
new const checkPointRadius = 15;
new
Float:randomAngle = float(random(360)),
Float:randomDistance = random(checkPointRadius);
new
Float:dropX = checkPointX + floatsin(-randomAngle, degrees) * randomDistance,
Float:dropY = checkPointY + floatcos(-randomAngle, degrees) * randomDistance,
Float:dropZ = checkPointZ + 0.5;
Something like that should work. This picks a random angle between 0 and 360 (a full circle, as you know) and a random distance between 0 and the size of the radius of the checkpoint. Then some trig is done to calculate the coordinates at the specified angle and the specified distance. Can't really explain that. Rather mathematically complex.
|
Thank you very much man. This helped a lot!