Getting random cordinates within a checkpoint
#1

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.
Reply
#2

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.
Reply
#3

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.
Reply
#4

PHP код:
new const checkPointRadius 15;

new 
    
Float:randomAngle float(random(360)),
    
Float:randomDistance random(checkPointRadius); 

new
    
Float:dropX checkPointX floatsin(-randomAngledegrees) * randomDistance,
    
Float:dropY checkPointY floatcos(-randomAngledegrees) * 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.
Reply
#5

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(-randomAngledegrees) * randomDistance,
    
Float:dropY checkPointY floatcos(-randomAngledegrees) * 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!
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)