[lua]
local v1,v2,v3,v4 = Vector(0,0,0), Vector(20,0,0), Vector(20,20,0), Vector(0,20,0) --should create a square unless im an idiot
--how do I get a random point between those 4?
[/lua]
I thought of lerping v1 and v2 by a random fraction then lerping v3 and v4 and creating a vector from that, will that work though? I'm away so unable to test.
[lua]
local function randomfloat(dec, min, max)
return math.random(min * dec, max * dec) / dec;
end
function RandomBetween(decimal, ...)
local vecs = {...};
local cvec = vecs[1];
local minx, maxx, miny, maxy, minz, maxz = cvec.x, cvec.x, cvec.y, cvec.y, cvec.z, cvec.z;
local x,y,z;
for i = 2, #vecs do
cvec = vecs[i];
x, y, z = cvec.x, cvec.y, cvec.z;
if(x < minx) then
minx = x;
elseif(x > maxx) then
maxx = x;
end
if(y < miny) then
miny = y;
elseif(y > maxy) then
maxy = y;
end
if(z < minz) then
minz = z;
elseif(z > maxz) then
maxz = z;
end
end
return Vector(randomfloat(decimal minx,maxx), randomfloat(decimal,minx,maxx), randomfloat(decimal,minx,maxx));
end
[/lua]
try that
Why not create a vector with math.random (int) or math.Rand (float)
[code]
local BoxMinX = 0
local BoxMaxX = 20
local BoxMinY = 0
local BoxMaxY = 20
local BoxMinZ = 0
local BoxMaxZ = 0
RandomVector = Vector(math.random(BoxMinX,BoxMaxX),math.random(BoxMinY,BoxMaxY),math.random(BoxMinZ,BoxMaxZ))
[/code]
EDIT: Ninja'd
Sorry, you need to Log In to post a reply to this thread.