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.

local yoffset = 1    
local minx = (v.Baseplate.Size.X / 2) - v.Baseplate.Position.X
local maxx = (v.Baseplate.Size.X / 2) + v.Baseplate.Position.X
local minz = (v.Baseplate.Size.Z / 2) - v.Baseplate.Position.Z
local maxz = (v.Baseplate.Size.Z / 2) + v.Baseplate.Position.Z
local y = (v.Baseplate.Size.Y / 2) + v.Baseplate.Position.Y + yoffset

local randX = mainrand.RandomMINMAX(minx,maxx)
local randZ = mainrand.RandomMINMAX(minz,maxz)

local clone = q.Asset:Clone()

print("located at minimum "..minx.." maximum "..maxx..",".." "..minz.." "..maxz)
clone.Position = Vector3.new(randX,y,randZ)
clone.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:

math.randomseed(tick())

local target = workspace.Baseplate
local x = math.random(target.position.X - target.Size.X / 2, target.position.X + target.Size.X / 2)
local 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