Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to situate a part on a random point on another part?

Asked by 5 years ago

Heres my code.

01local yoffset = 1   
02local minx = (v.Baseplate.Size.X / 2) - v.Baseplate.Position.X
03local maxx = (v.Baseplate.Size.X / 2) + v.Baseplate.Position.X
04local minz = (v.Baseplate.Size.Z / 2) - v.Baseplate.Position.Z
05local maxz = (v.Baseplate.Size.Z / 2) + v.Baseplate.Position.Z
06local y = (v.Baseplate.Size.Y / 2) + v.Baseplate.Position.Y + yoffset
07 
08local randX = mainrand.RandomMINMAX(minx,maxx)
09local randZ = mainrand.RandomMINMAX(minz,maxz)
10 
11local clone = q.Asset:Clone()
12 
13print("located at minimum "..minx.." maximum "..maxx..",".." "..minz.." "..maxz)
14clone.Position = Vector3.new(randX,y,randZ)
15clone.Parent = v.Extras

https://gyazo.com/380924e4ebc236fbf150faa95116248a The rocks are supposed to be on the sand.

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

You could do something like this:

1math.randomseed(tick())
2 
3local target = workspace.Baseplate
4local x = math.random(target.position.X - target.Size.X / 2, target.position.X + target.Size.X / 2)
5local z = math.random(target.position.Z - target.Size.Z / 2, target.position.Z + target.Size.Z / 2)
0
Why did I never get this until 5 days later? RunKittenzRComin 170 — 5y
Ad

Answer this question