Is there a way to make something appear within a random radius? I know the easiest way might be to make a random x and y, but then it would appear inside a rectangle randomly. For example, make an object appear such that the distance from it to the center of the point is not over, say, 90. [import]uid: 147322 topic_id: 28354 reply_id: 328354[/import]
objX = math.random(90)
objY = math.random(90)
while math.sqrt( (objX - centerX)\*(objX - centerX) + (objY - centerY)\*(objY - centerY)) \> 90 do
objX = math.random(90)
objY = math.random(90)
end
Of course you want to probably put something in that while loop to prevent it from running too long if the random number generator starts spewing really high numbers.
Another way to do this would be to generate a random radius and random angle and calculate the X, Y based on that.
[import]uid: 19626 topic_id: 28354 reply_id: 114602[/import]
Works like a charm, only one problem. For it to work, you have to specify a bottom number, like this:
[lua] objX = math.random(-90, 90) – your solution was only filling in the bottom right quarter of the circle
objY = math.random(-90, 90)
while math.sqrt( (objX - centerX)*(objX - centerX) + (objY - centerY)*(objY - centerY)) > 90 do
objX = math.random(-90, 90)
objY = math.random(-90, 90)
end[/lua]
Thanks Rob!
binc [import]uid: 147322 topic_id: 28354 reply_id: 114605[/import]
Hey, I’m getting a lot of crashes with that. How might I do the second option? The first one works pretty well, but it crashes every now and them. [import]uid: 147322 topic_id: 28354 reply_id: 116890[/import]